jowy / tactician-service-provider
Silex tactician service provider
Installs: 3 168
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 6
Open Issues: 0
Requires
- php: ~5.5
- league/tactician: ~1.0.0
- silex/silex: ~2.0
This package is not auto-updated.
Last update: 2024-09-28 17:38:23 UTC
README
Provides Tactician as service to Pimple or Silex Container
Requirements
- PHP >= 5.5
- Silex >= 2.0
- Pimple >= 3.0
Installation
composer require jowy/tactician-service-provider
Usage
Register tactician service provider
$app->register( new TacticianServiceProvider( [ 'tactician.inflector' => 'class_name', 'tactician.middleware' => [ new LockingMiddleware() ] ] ) );
Register command handler in DIC
Handler must registered in container and use FQCN
as service id
$app[HandlerClass::class] = function() { return new HandlerClass(); };
Map command and handler
after tactician commadn bus service provider registered, you can map command and handler
$app['tactician.locator']->addHandler(CommandClass::class, HandlerClass::class);
Dispatching Command
$command = new CommandClass('param'); $container['tactician.command_bus']->handle($command)
Options
Inflector
- class_name
- class_name_without_suffix
- handle
- invoke
For more information for choosing Inflector
please refer to this documentation
Middleware
Middleware can be added while tactician service registered was registered.
$app->register( new TacticianServiceProvider( [ 'tactician.inflector' => 'class_name', 'tactician.middleware' => [ new LockingMiddleware(), new SomeMiddleware(), new OtherMiddleware() ] ] ) );
Optionally lazy initialization for middleware is possible by using this method
$app[LockingMiddleware::class] = function () { return new LockingMiddleware(); }; $app->register( new TacticianServiceProvider( [ 'tactician.inflector' => 'class_name', 'tactician.middleware' => [ LockingMiddleware::class ] ] ) );
License
MIT, see LICENSE