2017 © Pedro Peláez
 

library tactician-pimple

Tactician command locator for the Pimple DI container

image

bezdomni/tactician-pimple

Tactician command locator for the Pimple DI container

  • Saturday, January 23, 2016
  • by ihabunek
  • Repository
  • 1 Watchers
  • 5 Stars
  • 12,755 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Tactician Pimple Locator

Allows lazy loading of command handlers from a Pimple dependency injection container., (*1)

Travis Packagist Packagist, (*2)

Install

Install via composer, (*3)

composer require bezdomni/tactician-pimple

Usage

Presuming you have a couple of commands: UserAddCommand, UserDeleteCommand, and corresponding handlers UserAddHandler, UserDeleteHandler., (*4)

use Bezdomni\Tactician\Pimple\PimpleLocator;
use League\Tactician\CommandBus;
use League\Tactician\Handler\CommandHandlerMiddleware;
use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor;
use League\Tactician\Handler\MethodNameInflector\HandleInflector;
use Pimple\Container;

// Create a container and configure the handlers on it
$container = new Container();
$container['handlers.user.add'] = function () {
    echo "Creating AddUserHandler\n";
    return new AddUserHandler();
};
$container['handlers.user.delete'] = function () {
    echo "Creating DeleteUserHandler\n";
    return new DeleteUserHandler();
};

// Map command class names to container keys holding corresponding handlers
$locatorMap = [
    AddUserCommand::class => 'handlers.user.add',
    DeleteUserCommand::class => 'handlers.user.delete',
];

// Create the locator
$locator = new PimpleLocator($container, $locatorMap);

// Create a command handler middleware using the pimple locator
$middleware = new CommandHandlerMiddleware(
    new ClassNameExtractor(),
    $locator,
    new HandleInflector()
);

// Create the command bus using the middleware, and you're ready to go
$commandBus = new CommandBus([$middleware]);

// Create and run commands on the command bus
$addUserCommand = new AddUserCommand();
$deleteUserCommand = new DeleteUserCommand();

$commandBus->handle($addUserCommand);
$commandBus->handle($deleteUserCommand);

License

The MIT License (MIT). Please see License File for more information., (*5)

The Versions

23/01 2016

dev-master

9999999-dev

Tactician command locator for the Pimple DI container

  Sources   Download

MIT

The Requires

 

The Development Requires

container league pimple locator tactician

23/01 2016

1.0.0

1.0.0.0

Tactician command locator for the Pimple DI container

  Sources   Download

MIT

The Requires

 

The Development Requires

container league pimple locator tactician