trntv / yii2-tactician
一个简单、灵活的命令总线。此包提供与 Yii2 的集成
1.0.1
2018-02-03 18:03 UTC
Requires
- league/tactician: ^0.6.0
- yiisoft/yii2: ~2.0.13
This package is auto-updated.
Last update: 2024-09-22 09:08:21 UTC
README
Tactician 是一个简单、灵活的包,允许您轻松在应用程序中实现命令总线模式。此包提供与 Yii2 的基本集成
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require trntv/yii2-tactician
或者将以下内容添加到您的 composer.json
文件的 require 部分中。
"trntv/yii2-tactician": "*"
用法
在您的配置文件中某个地方
'components' => [ ... 'commandBus' => [ 'class' => '\trntv\tactician\Tactician', 'commandNameExtractor' => '\League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor' 'methodNameInflector' => '\League\Tactician\Handler\MethodNameInflector\HandleInflector' 'commandToHandlerMap' => [ 'app\commands\command\SendEmailCommand' => 'app\commands\handler\SendEmailHandler' ], 'middlewares' => [ ... ] ] ... ]
在您的应用程序中某个地方
Yii::$app->commandBus->handle(new SendEmailCommand([ 'from' => 'email@example.org', 'to' => 'user@example.org', 'body' => '...' ])) Yii::$app->commandBus->handleMultiply([ new SendEmailCommand([ 'from' => 'email@example.org', 'to' => 'user@example.org', 'body' => '...' ]), new SomeOtherCommand([ ... ]) ])