d2g /reactor
此包最新版本(v0.2.0)没有提供许可证信息。
v0.2.0
2017-01-29 22:26 UTC
Requires
- php: >=5.4
- league/climate: ^3.2
This package is not auto-updated.
Last update: 2024-09-24 18:18:06 UTC
README
## PHP 命令行微框架
为什么还需要另一个命令行工具?
因为我没有找到足够简单易用的工具。在我看来,这个框架相当简单,可以处理大部分我所能想到的命令行需求。
创建你的命令行
扩展 reactor 命令类
class Mycommand extends \D2G\Reactor\Command
定义你的方法和所需的参数/选项
function __construct($args, $opts, $flags) { parent::construct($args, $opts, $flags); $this->commands = array( '<pre>__DEFAULT__</pre>'=>'__help', // the name of your method 'my_method'=>array( // defining expected inputs 'expecting'=>array( // defining expected arguments 'args'=>array( array( // used in error message 'name'=>'my-argument', // internal function will try to cast the argument to this type 'type'=>'type of argument', // command will fail if an expected argument is not present 'required'=>true|false ) ), // defining expected options 'opts'=>array( // option name used in cli prefixed with -- 'option-name'=>array( // internal function will try to cast the argument to this type 'type'=>'string', // command will fail if an expected argument is not present 'required'=>true|false // default value assigned to the options if not given 'default'=>'' ) ) // defining expected flags 'args'=>array( array( // flags 'a', 'longflag' ) ), ), ) ); }
用法
基本
在*nix系统上
[php ][vendor/bin/]reactor Your/Command/Class/FQN/With/Slashes:yourCommandMethod firstArg secondArg --myOption=myOptionValue --myOtherOpt="value encapsed" -longFlag -a