hellofresh/tactician-service-provider

This package is abandoned and no longer maintained. No replacement package was suggested.

Silex tactician service provider

v2.1.1 2016-06-20 16:31 UTC

README

Scrutinizer Code Quality Build Status

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