定制 fyre/command 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

$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.

  • $namespace is 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.

  • $argv is an array containing the CLI arguments.
$code = $runner->handle($argv);

Has Command

Determine whether a command exists.

  • $alias is a string representing the command alias.
$hasCommand = $runner->hasCommand($alias);

Has Namespace

Determine whether a namespace exists.

  • $namespace is a string representing the namespace.
$hasNamespace = $runner->hasNamespace($namespace);

Remove Namespace

Remove a namespace.

  • $namespace is a string representing the namespace.
$runner->removeNamespace($namespace);

Run

Run a Command.

  • $alias is a string representing the command alias.
  • $arguments is 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.

  • prompt is a string representing the prompt text, and will default to "".
  • values is an array containing the values, and will default to null.
  • required is a boolean indicating whether a value must be provided, and will default to false.
  • as is a string representing the value type, and will default to null.
  • default is 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 fyre/command 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 168
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-07