trntv/yii2-tactician

A simple, flexible command bus. This package provide it's integration with Yii2

Installs: 43 951

Dependents: 0

Suggesters: 0

Security: 0

Stars: 14

Watchers: 4

Forks: 6

Open Issues: 0

Type:yii2-extension

1.0.1 2018-02-03 18:03 UTC

This package is auto-updated.

Last update: 2024-10-22 09:20:32 UTC


README

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