Download the PHP package kentaro-a/phpcommander without Composer
On this page you can find all versions of the php package kentaro-a/phpcommander. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kentaro-a/phpcommander
More information about kentaro-a/phpcommander
Files in kentaro-a/phpcommander
Package phpcommander
Short Description PHP Command line interface. Easy to handle flags and options.
License MIT
Homepage https://github.com/kentaro-a/PHPCommander
Informations about the package phpcommander
PHPCommander
Easy to handle flags and options which passed through by $argv. Flags and options have to be start with "-" or "--". If you've already have any classes and you'd like to make something like CLI batches with it, PHPCommander makes it easy.
Requirements
- php >= 7.1
Install
How To Use
Make Flags for command
Use new Flg(string $flg, bool $must=false, string $help="", array $validators=[]) to make Flag. you can make custom validator class like preset validator ValidatorNotEmptyString.
param | desc |
---|---|
$flg | require, this must start with - or -- |
$must | optional default=false, if true check for being passed flg in cli args. |
$help | optional default="", help text to be shown. |
$validators | optional default=[], an array of sub classes of Validator to validate flg. |
You can make Procedure which implements ProcedureInterface.
Make Command
After making Procedure you can set it into Command. Using new Command(string $command_name, ProcedureInterface $procedure, Flgs $flgs=null, string $description="").
param | desc |
---|---|
$command_name | require, this must not start with - or -- |
$procedure | require, procedure to be called when command passed. |
$flgs | optional default=null, Flgs class contains an array of Flg classes. |
$description | optional default="", description text to be shown in help. |
Add Commands into Commander and invoke registered command.
Commander::invoke obtains command name and options from $argv then invokes relevant Procedure::__invoke().
Show help.
You can show registered command list without any parameters.
You can also pass the reserved flg after command_name like -h or --help to show help.
Detail
See examples.