kasundon / lib-console
此软件包的最新版本(0.0.6)没有可用的许可证信息。
0.0.6
2015-05-26 13:13 UTC
This package is not auto-updated.
Last update: 2024-10-02 10:02:02 UTC
README
简单的PHP CLI框架
#安装有两种方式可以使用lib-console。
####1. 使用Composer composer.json文件
{ "require": { "kasundon/lib-console": "~0.0.6" } }
php composer.phar install
####2. 使用PHAR存档(console.phar)首先,下载最新的console.phar
。
curl -O https://github.com/KasunDon/lib-console/raw/master/build/console.phar
####获取console.phar
的帮助
php console.phar -help
设置默认命令文件路径
将console.json
文件放置在当前工作目录。留空file_path
以使用当前工作目录。
{ "file_path": "commands/" }
编写命令
只需在您的自定义命令类上实现Command
接口。
####如果使用console.phar
- 不要忘记在实现Command
接口之前添加以下语句。
require_once 'phar://console.phar/Command.php';
###标准自定义命令
<?php class Test implements Command { /** * Pre-execution command setup */ public function setup() { CommandUtility::log("pre command setup"); } /** * Executes command routines */ public function execute() { CommandUtility::log("execute"); } /** * Returns command name/description * * @return string */ public function getCommand() { return "Test Command"; } }
#运行命令将app.php
放入当前工作目录并按照以下格式执行。第一个参数是您的自定义命令名称。传递参数时使用以下格式--abc 1
。
请注意:类名将用作命令名称。
php app.php Test --abc 1
或使用console.phar
php console.phar Test --abc 1
#在命令脚本中使用cli参数lib-console自动将输入cli参数注入到arguments
属性。您可以直接使用它们,如下所示,
$this->arguments
##如果您有任何疑问,请随时贡献/反馈 ###如有任何问题,请随时联系kasun@phpbox.info