Total Complexity | 6 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
15 | abstract class AbstractEventDispatcher implements EventDispatcherInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var ListenerProviderInterface |
||
19 | */ |
||
20 | protected $listenerProvider; |
||
21 | |||
22 | /** |
||
23 | * Trigger the registered collection of events. |
||
24 | * |
||
25 | * @param object $event The event that should be triggered. |
||
26 | * |
||
27 | * @return object |
||
28 | * |
||
29 | * @throws \Throwable If an event listener throws an exception |
||
30 | */ |
||
31 | public function dispatch(object $event): object |
||
32 | { |
||
33 | if ($this->isPropagationStopped($event)) { |
||
34 | return $event; |
||
35 | } |
||
36 | |||
37 | foreach ($this->listenerProvider->getListenersForEvent($event) as $listener) { |
||
38 | $listener($event); |
||
39 | |||
40 | if ($this->isPropagationStopped($event)) { |
||
41 | break; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | return $event; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Check if the event propagation has been stopped. |
||
50 | * |
||
51 | * @param object $event |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | protected function isPropagationStopped(object $event): bool |
||
58 | } |
||
59 | } |
||
60 |