akmaks/command-chaining-bundle

该组件提供了一些功能,用于链式调用控制台命令

安装: 23

依赖: 0

建议者: 0

安全性: 0

星星: 0

关注者: 1

分支: 0

类型:symfony-bundle

dev-master 2021-05-25 22:26 UTC

This package is auto-updated.

Last update: 2024-09-26 06:11:07 UTC


README

该组件提供了一些功能,用于链式调用控制台命令

安装

  1. 安装包
composer require akmaks/command-chaining-bundle
  1. 创建文件 config/packages/akmaks_command_chaining.yaml 并配置你的链式命令
parameters:
    chains:
        App\UI\Console\FirstMainCommand:
            - App\UI\ConsoleSecondCommand
            - App\UI\ConsoleThirdCommand
            - App\UI\ConsoleSecondCommand
        App\UI\Console\SecondMainCommand:
            - App\UI\ConsoleSecondCommand
            - App\UI\ConsoleThirdCommand
            - App\UI\ConsoleSecondCommand
  1. 在链式命令中实现 CommandChainingInterface

对于主命令

class CreateCommand extends Command implements CommandChainingInterface
...
    public function isMasterCommand(): bool
    {
        return true;
    }

对于链式命令

class ConsoleSecondCommand extends Command implements CommandChainingInterface
...
    public function isMasterCommand(): bool
    {
        return false;
    }
...
  1. 检查结果
bin/console app:first:main
[2021-05-25 21:07:25]: app:first:main is a master command of a command chain that has registered member commands
[2021-05-25 21:07:25]: app:first:second, app:first:third, app:first:second: are registered as a members of app:first:main command chain
[2021-05-25 21:07:25]: Executing app:first:main command itself first
[2021-05-25 21:07:25]: Executing app:first:main chain members
[2021-05-25 21:07:25]: Execution of app:first:main chain completed