Download the PHP package mikemix/tactician-module without Composer
On this page you can find all versions of the php package mikemix/tactician-module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mikemix/tactician-module
More information about mikemix/tactician-module
Files in mikemix/tactician-module
Package tactician-module
Short Description Laminas/Mezzio Module to use the League of Extraordinary Packages' Tactician library - flexible command bus implementation
License MIT
Informations about the package tactician-module
Tactician Laminas/Mezzio Module
Wrapper module for easy use of the Tactician Command Bus in your Laminas or Mezzio applications.
Installation
Best install with Composer:
Register as Laminas Framework module inside your file using TacticianModule
name.
You can also use this package as Mezzio module by TacticianModule\ConfigProvider
Using
The module presents a Controller Plugin called tacticianCommandBus()
for easy use of dispatching commands. If no command object is passed to it, the CommandBus object will be returned. If you pass the command however, it will be passed over to the CommandBus and handled, and the output from the handler will be returned.
You can type hint this plugin in your controller, for example: .
You can inject the CommandBus
into yout service layer through a factory by simply requesting the League\Tactician\CommandBus::class
from the Container.
Configuring
The module ships with a LaminasLocator
and a CommandHandlerMiddleware
and a HandlerInflector
configured as default. If you wish to override the default locator or default command bus implementations, then simply use the tactician
key in the merged config.
default-extractor
, default-locator
and default-inflector
are service manager keys to registered services.
LaminasLocator
expects handlers in the handler-map
to be commandName => serviceManagerKey
or commandName => Handler_FQCN
, altough to prevent additional costly checks, use serviceManagerKey and make sure it is available as a Laminas Service.
To add custom middleware to the middleware stack, add it to the middleware
array as ServiceName
=> priority
in which the middleware are supposed to be executed (higher the number, earlier it will execute). For example
Basic usage
Basicly, all you probably will want to do, is to define the handler-map
array in your module's configuration. For example:
Plugins
LockingMiddleware
The LockingMiddleware can now be used out of the box.
Simply add the League\Tactician\Plugins\LockingMiddleware
FQCN to the TacticianModule's middleware configuration with
appropriate priority. You probably want to execute it before the CommandHandlerMiddleware
:
TransactionMiddleware
The TransactionMiddleware can now be used out of the box.
Simply add the League\Tactician\Doctrine\ORM\TransactionMiddleware
FQCN to the TacticianModule's middleware configuration with
appropriate priority. You probably want to execute it before the CommandHandlerMiddleware
and after the LockingMiddleware
:
Changing the Handler Locator
ClassnameLaminasLocator
This locator simply appends the word Handler
to the command's FQCN so you don't have to define any handler map. For example, if you request command App\Commands\LoginCommand
, locator will try to get App\Command\LoginCommandHandler
from the Service Manager.
Locator will work with FQCN's not registered in the Service Manager, altough to prevent additional costly checks, make sure the locator is registered as a invokable or factory.
To change the locator from LaminasLocator to ClassnameLaminasLocator simply set it in the config: