Download the PHP package pavelmics/yii-tactician without Composer
On this page you can find all versions of the php package pavelmics/yii-tactician. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pavelmics/yii-tactician
More information about pavelmics/yii-tactician
Files in pavelmics/yii-tactician
Package yii-tactician
Short Description Yii adapter for league/tactician command bus pattern implimentation
License MIT
Homepage https://github.com/pavelmics/YiiTactician
Informations about the package yii-tactician
Yii-Tactician
Yii-Tactician is yii addapter for Tactician command bus library. It provides an easy way to use the command bus pattern in Yii-based apps.
Installation
You can install Yii-Tactician via composer by running
composer require pavelmics/yii-tactician
or just add
"pavelmics/yii-tactician": "0.1.1"
to your composer.json file.
Configuration
Once the library is installed, modify your application configuration as follows:
By default Yii Tactician uses bus_commands directory for storing command handlers, you can change this by configuring handlersPath
with array of yii-aliases as follow:
NOTE: don't use * aliases, your aliases must point to a dirrectory but not a file!
NOTE2: Also you have to use psr-4 autoload system to use Yii-Tactician (just add require('path/to/vendor/autoload.php');
to your index.php and console.php).
Usage
Basic
Define a command class somewhere in your application, for example:
Then, define a handler class under one of your handlers path (see configuration section of this readme). The name of handler class must be the same as the name of command class suffixed with "Handler". For example for class TestCommand
we need to define TestCommandHandler
class:
Now we can use this command in controllers (or wherever you want):
Controller based handlers
Sometimes we need handle one command in several different ways. Let's say we need to register users. Sometimes users register by email and sometimes by phone number. We need to handle register command almost the same but at the same time a bit different. To achive this we can define several handler-functions in handler class (like in standart Yii controller). For example:
And then use YiiTactician\ControllerBaseCommand
to define your command class:
Now you can do something like this: