fyre/command
Composer 安装命令:
composer require fyre/command
包简介
A command library.
README 文档
README
FyreCommand is a free, open-source CLI command library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/command
In PHP:
use Fyre\Command\CommandRunner;
Basic Usage
$containeris a Container.$inflectoris an Inflector.$loaderis a Loader.$iois a Console.$eventManageris an EventManager.$typeParseris an TypeParser.
$runner = new CommandRunner($container, $inflector, $loader, $io, $eventManager, $typeParser);
Autoloading
It is recommended to bind the CommandRunner to the Container as a singleton.
$container->singleton(CommandRunner::class);
Any dependencies will be injected automatically when loading from the Container.
$runner = $container->use(CommandRunner::class);
Methods
Add Namespace
Add a namespace for loading commands.
$namespaceis a string representing the namespace.
$runner->addNamespace($namespace);
All
Get all available commands.
$commands = $runner->all();
Clear
Clear all namespaces and loaded commands.
$runner->clear();
Get Namespaces
Get the namespaces.
$namespaces = $runner->getNamespaces();
Handle
Handle an argv Command.
$argvis an array containing the CLI arguments.
$code = $runner->handle($argv);
Has Command
Determine whether a command exists.
$aliasis a string representing the command alias.
$hasCommand = $runner->hasCommand($alias);
Has Namespace
Determine whether a namespace exists.
$namespaceis a string representing the namespace.
$hasNamespace = $runner->hasNamespace($namespace);
Remove Namespace
Remove a namespace.
$namespaceis a string representing the namespace.
$runner->removeNamespace($namespace);
Run
Run a Command.
$aliasis a string representing the command alias.$argumentsis an array containing arguments for the command, and will default to [].
$code = $runner->run($alias, $arguments);
Command options will be parsed from the provided arguments.
Commands
Custom commands can be created by extending \Fyre\Command\Command, suffixing the class name with "Command", and ensuring a run method is implemented.
Any dependencies will be resolved automatically from the Container.
The run method should return an integer representing the command exit code. The class constants Command::CODE_SUCCESS and Command::CODE_ERROR can be used.
Aliases
You can define $alias and $description properties on the command. If no $alias is a provided, the command class name will be used (converted to snake_case).
Options
You can also define an $options array on your custom commands, which will be used by the CommandRunner to parse the arguments and prompt for input if required.
promptis a string representing the prompt text, and will default to "".valuesis an array containing the values, and will default to null.requiredis a boolean indicating whether a value must be provided, and will default to false.asis a string representing the value type, and will default to null.defaultis the default value, and will default to true.
protected array $options = [ 'name' => [ 'prompt' => 'What is your name?', 'required' => true, ], 'color' => [ 'prompt' => 'What is your favorite color?', 'values' => [ 'red', 'green', 'blue', ], ], 'confirmed' => [ 'prompt' => 'Do you want to continue?', 'as' => 'boolean', 'required' => true, ], ]; public function run(string $name, string|null $color, bool $confirmed): int;
If an option is marked as required and not provided as an argument, the CommandRunner will prompt for the value, otherwise the default value will be used.
fyre/command 适用场景与选型建议
fyre/command 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 168 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fyre/command 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fyre/command 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 168
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-07