Skip to content

trntv/yii2-tactician

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Tactician

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

Installation

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.

Usage

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([
        ...
    ])
])