1 | <?php |
||
24 | class CommandHandlerManager implements CommandHandlerManagerInterface |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * @var CommandHandlerInterface[] $command_handlers |
||
29 | */ |
||
30 | protected $command_handlers; |
||
31 | |||
32 | /** |
||
33 | * @type LoaderInterface $loader |
||
34 | */ |
||
35 | private $loader; |
||
36 | |||
37 | |||
38 | |||
39 | /** |
||
40 | * CommandHandlerManager constructor |
||
41 | * |
||
42 | * @param LoaderInterface $loader |
||
43 | */ |
||
44 | public function __construct(LoaderInterface $loader) |
||
48 | |||
49 | |||
50 | |||
51 | /** |
||
52 | * By default, Commands and CommandHandlers would normally |
||
53 | * reside in the same folder under the same namespace, |
||
54 | * and the names of the two classes would only differ in that |
||
55 | * one ends in "Command" and the other ends in "CommandHandler". |
||
56 | * However, if you wanted to utilize a CommandHandler from somewhere else, |
||
57 | * then this method allows you to add that CommandHandler and specify the FQCN |
||
58 | * (Fully Qualified ClassName) for the Command class that it should be used for. |
||
59 | * For example: |
||
60 | * by default the "Vendor\some\namespace\DoSomethingCommand" |
||
61 | * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
||
62 | * but if you wanted to instead process that commend using: |
||
63 | * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
||
64 | * then the following code: |
||
65 | * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
||
66 | * $CommandHandlerManager->addCommandHandler( |
||
67 | * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
||
68 | * 'Vendor\some\namespace\DoSomethingCommand' |
||
69 | * ); |
||
70 | * would result in the alternate CommandHandler being used to process that Command |
||
71 | * |
||
72 | * @param CommandHandlerInterface $command_handler |
||
73 | * @param string $fqcn_for_command Fully Qualified ClassName for Command |
||
74 | * @return void |
||
75 | * @throws InvalidCommandHandlerException |
||
76 | */ |
||
77 | public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
||
87 | |||
88 | |||
89 | |||
90 | /** |
||
91 | * @param CommandInterface $command |
||
92 | * @param CommandBusInterface $command_bus |
||
93 | * @return mixed |
||
94 | * @throws DomainException |
||
95 | * @throws CommandHandlerNotFoundException |
||
96 | */ |
||
97 | public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
||
130 | |||
131 | |||
132 | } |
||
133 | // End of file CommandHandlerManager.php |
||
134 | // Location: core/services/commands/CommandHandlerManager.php |