Tactician is a simple, flexible package allows you to easy implement Command Bus pattern in your application. This package provide it's very basic integration with Yii2
The preferred way to install this extension is through composer.
Either run
php composer.phar require trntv/yii2-tactician
or add
"trntv/yii2-tactician": "*"
to the require section of your composer.json
file.
Somewhere in your config:
'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' => [
...
]
]
...
]
Somewhere in your app:
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([
...
])
])