The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

Plugins

Container

Author Source Packagist

This plugin adds support for lazy-loading Command Handlers from a container. If you’re using a container (that is an implementation of the container-interop ContainerInterface) in your project, this plugin will likely improve your memory usage and startup times compared to the InMemoryHandlerLocator that Tactician ships with by default.

Setup has a few steps but it isn’t very complicated:

// Map your command classes to the container id of your handler. When using
// League\Container, the container id is typically the class or interface name
$commandToHandlerMap = [
    RentMovieCommand::class => RentMovieHandler::class
];

// Next we create a new Tactician ContainerLocator, passing in both
// a fully configured container instance and the map.
use League\Tactician\Container\ContainerLocator;
$containerLocator = new ContainerLocator(
    $container,
    $commandToHandlerMap
);

// Finally, we pass the ContainerLocator into the CommandHandlerMiddleware that
// we use in almost every CommandBus.
$commandHandlerMiddleware = new CommandHandlerMiddleware(
    new ClassNameExtractor(),
    $containerLocator,
    new HandleInflector()
)

// And that's it! Drop it in our command bus and away you go.
$commandBus = new CommandBus(
    [
        // your other middlewares...
        $commandHandlerMiddleware,
    ]
);