1 | <?php |
||
10 | final class CommandDispatcher implements CommandDispatcherInterface |
||
11 | { |
||
12 | /** |
||
13 | * List of command handler subscribed per command. |
||
14 | * This is mainly used for debug (exceptions). |
||
15 | * |
||
16 | * @var CommandHandlerInterface[] |
||
17 | */ |
||
18 | private $handlers = []; |
||
19 | /** |
||
20 | * List of methods to call when a command is triggered. |
||
21 | * |
||
22 | * @var callable[] |
||
23 | */ |
||
24 | private $handlingMethods = []; |
||
25 | |||
26 | /** |
||
27 | * Get the handler link to the command (if any) and run the callable associated. |
||
28 | * This method will try to look for handlers registered to: |
||
29 | * - the command class name |
||
30 | * - a parent of the current command |
||
31 | * - an interface that the current command may implement. |
||
32 | * |
||
33 | * @param AbstractCommand $command |
||
34 | * |
||
35 | * @return AbstractCommand |
||
36 | */ |
||
37 | public function handle(AbstractCommand $command) |
||
52 | |||
53 | /** |
||
54 | * @param CommandHandlerInterface $handler |
||
55 | */ |
||
56 | public function register(CommandHandlerInterface $handler) |
||
76 | |||
77 | /** |
||
78 | * @return CommandHandlerInterface[] |
||
79 | */ |
||
80 | public function getHandlers() |
||
84 | |||
85 | /** |
||
86 | * @param AbstractCommand $command |
||
87 | * |
||
88 | * @return callable[] |
||
89 | */ |
||
90 | private function getHandlingMethodForCommand(AbstractCommand $command) |
||
94 | |||
95 | /** |
||
96 | * @param AbstractCommand $command |
||
97 | * |
||
98 | * @return CommandHandlerInterface[] |
||
99 | */ |
||
100 | private function getHandlerForCommand(AbstractCommand $command) |
||
104 | |||
105 | /** |
||
106 | * @param array $property |
||
107 | * @param AbstractCommand $command |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | private function filterForCommand(array $property, AbstractCommand $command) |
||
124 | } |
||
125 |