InMemoryLocator
in package
implements
HandlerLocator
Fetch handler instances from an in-memory collection.
This locator allows you to bind a handler object to receive commands of a certain class name. For example:
// Wire everything together
$myHandler = new TaskAddedHandler($dependency1, $dependency2);
$inMemoryLocator->addHandler($myHandler, 'My\TaskAddedCommand');
// Returns $myHandler
$inMemoryLocator->getHandlerForCommand('My\TaskAddedCommand');
Interfaces, Classes and Traits
- HandlerLocator
- Service locator for handler objects
Table of Contents
- $handlers : array<string|int, object>
- __construct() : mixed
- addHandler() : mixed
- Bind a handler instance to receive all commands with a certain class
- getHandlerForCommand() : object
- Returns the handler bound to the command's class name.
- addHandlers() : mixed
- Allows you to add multiple handlers at once.
Properties
$handlers
protected
array<string|int, object>
$handlers
= []
Methods
__construct()
public
__construct([array<string|int, mixed> $commandClassToHandlerMap = [] ]) : mixed
Parameters
- $commandClassToHandlerMap : array<string|int, mixed> = []
Return values
mixed —addHandler()
Bind a handler instance to receive all commands with a certain class
public
addHandler(object $handler, string $commandClassName) : mixed
Parameters
- $handler : object
-
Handler to receive class
- $commandClassName : string
-
Command class e.g. "My\TaskAddedCommand"
Return values
mixed —getHandlerForCommand()
Returns the handler bound to the command's class name.
public
getHandlerForCommand(string $commandName) : object
Parameters
- $commandName : string
Return values
object —addHandlers()
Allows you to add multiple handlers at once.
protected
addHandlers(array<string|int, mixed> $commandClassToHandlerMap) : mixed
The map should be an array in the format of: [ AddTaskCommand::class => $someHandlerInstance, CompleteTaskCommand::class => $someHandlerInstance, ]
Parameters
- $commandClassToHandlerMap : array<string|int, mixed>