1 | <?php |
||
20 | class InMemoryLocator implements HandlerLocator |
||
21 | { |
||
22 | /** |
||
23 | * @var object[] |
||
24 | */ |
||
25 | protected $handlers = []; |
||
26 | |||
27 | /** |
||
28 | * @param array $commandClassToHandlerMap |
||
29 | */ |
||
30 | 5 | public function __construct(array $commandClassToHandlerMap = []) |
|
34 | |||
35 | /** |
||
36 | * Bind a handler instance to receive all commands with a certain class |
||
37 | * |
||
38 | * @param object $handler Handler to receive class |
||
39 | * @param string $commandClassName Command class e.g. "My\TaskAddedCommand" |
||
40 | */ |
||
41 | 3 | public function addHandler($handler, $commandClassName): void |
|
45 | |||
46 | /** |
||
47 | * Allows you to add multiple handlers at once. |
||
48 | * |
||
49 | * The map should be an array in the format of: |
||
50 | * [ |
||
51 | * AddTaskCommand::class => $someHandlerInstance, |
||
52 | * CompleteTaskCommand::class => $someHandlerInstance, |
||
53 | * ] |
||
54 | * |
||
55 | * @param array $commandClassToHandlerMap |
||
56 | */ |
||
57 | 5 | protected function addHandlers(array $commandClassToHandlerMap): void |
|
63 | |||
64 | /** |
||
65 | * Returns the handler bound to the command's class name. |
||
66 | * |
||
67 | * @param string $commandName |
||
68 | * |
||
69 | * @return object |
||
70 | */ |
||
71 | 4 | public function getHandlerForCommand($commandName) |
|
79 | } |
||
80 |