jwyuen/dotslash

此包已被废弃且不再维护。未建议替代包。

Dotslash:用于快速创建PHP命令行应用程序的工具

v0.3.2.4 2018-08-06 19:19 UTC

This package is not auto-updated.

Last update: 2021-09-13 11:20:10 UTC


README

这是什么?

这是一个PHP库,允许您快速在PHP中创建命令行脚本,具有大多数命令行脚本应有的便利性,例如

  • 日志记录
  • 失败时发送电子邮件通知
  • 轻松接收和解析命令行选项
  • 执行计时器
  • 美观的终端输出

此库主要是在优秀的Symfony Console库的基础上进行封装,但添加了一些Console库中没有的功能,例如日志记录、电子邮件通知和执行计时器。

目的是什么?

目的是简化命令行脚本的创建

安装

只需将其添加到您的composer.json中,例如

{
  "require": {
    "jwyuen/dotslash": "0.*"
  }
}

用法

创建一个继承自 \Dotslash\BaseCommand 类的类。您的类应扩展以下函数

// See: https://symfony.com.cn/doc/current/components/console/introduction.html
configure()

// Code to execute
executeCommand()

// Any input validation code you want.  Should return boolean, or optionally a
// custom string with the failure message you specify (only in the case of user
// input failing).  If validation passes, this should always return true.
checkValidInput()

// The path to a configuration file if you want to use logging and email
// notifications.  Should return a string if you have a config, or null if you
// don't want to use logging and email functionality
getConfigPath()

然后,您需要一个入口脚本,从该脚本中运行您的命令行脚本。示例位于sample/console.php

配置结构

如果您决定要启用日志记录和电子邮件功能,您需要创建一个具有以下名称和内容/结构的配置文件

示例 dotslash-config.php

<?php

return array(
  'ses-email' => array(
    'aws-access-key' => '<your_access_key_here>',
    'aws-secret-key' => '<your_secret_key_here>',
    'region' => 'us-east-1',
    'email-recipient' => 'dev@dev.com'
  ),
  'logging' => array(
    'log-directory' => '/home/user/logs/'
  )
);

从示例配置中可以看出,您需要一个AWS账户,通过简单电子邮件服务发送电子邮件。未来可能会支持其他电子邮件选项。