1 | <?php |
||
14 | class SequentialCommandBus implements CommandBusInterface |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var CommandHandlerLocatorInterface |
||
19 | */ |
||
20 | private $locator; |
||
21 | |||
22 | /** |
||
23 | * @var CommandInterface[] |
||
24 | */ |
||
25 | private $commandStack = array(); |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | private $executing = false; |
||
31 | |||
32 | /** |
||
33 | * @param CommandHandlerLocatorInterface $locator |
||
34 | */ |
||
35 | public function __construct(CommandHandlerLocatorInterface $locator) |
||
39 | |||
40 | /** |
||
41 | * Sequentially execute commands |
||
42 | * |
||
43 | * If an exception occurs in any command it will be put on a stack |
||
44 | * of exceptions that is thrown only when all the commands are processed. |
||
45 | * |
||
46 | * [@inheritdoc} |
||
47 | */ |
||
48 | public function dispatch(CommandInterface $command) |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function getRegisteredCommandHandlers() |
||
74 | |||
75 | /** |
||
76 | * @param CommandInterface $command |
||
77 | * @param bool $first |
||
78 | * |
||
79 | * @throws Exception |
||
80 | * @return AbstractAggregateRoot|null |
||
81 | */ |
||
82 | protected function invokeHandler(CommandInterface $command, $first) |
||
100 | |||
101 | /** |
||
102 | * Only throw the exception if this is the first dispatch of the sequential dispatching. |
||
103 | * If we have a sub-command that throw an exception, it should not prevent other sub-command to be executed. |
||
104 | * We may need to rollback the whole process. |
||
105 | * |
||
106 | * @param Exception $exception |
||
107 | * @param bool $first |
||
108 | * |
||
109 | * @throws \Exception |
||
110 | */ |
||
111 | protected function handleException(Exception $exception, $first) |
||
117 | } |
||
118 |