1 | <?php |
||
18 | class EventDispatcher extends ContainerAwareEventDispatcher |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var EventDispatcherInterface[] |
||
23 | */ |
||
24 | private $catchall = []; |
||
25 | |||
26 | /** |
||
27 | * @Inject({"@service_container"}) |
||
28 | * @param ContainerInterface $container |
||
29 | */ |
||
30 | 9 | public function __construct(ContainerInterface $container) |
|
34 | |||
35 | /** |
||
36 | * @param EventDispatcherInterface $dispatcher |
||
37 | */ |
||
38 | 1 | public function addCatchall(EventDispatcherInterface $dispatcher) |
|
39 | { |
||
40 | 1 | $this->catchall[] = $dispatcher; |
|
41 | 1 | } |
|
42 | |||
43 | /** |
||
44 | * @param string $eventName |
||
45 | * @param Event $event |
||
46 | * @return Event |
||
47 | */ |
||
48 | 1 | public function dispatch($eventName, Event $event = null) |
|
49 | { |
||
50 | 1 | if (empty($event)) { |
|
51 | 1 | throw new RuntimeException('You have to pass an Event into EventDispatcher::dispatch'); |
|
52 | } |
||
53 | |||
54 | foreach ($this->catchall as $dispatcher) { |
||
55 | $dispatcher->dispatch($eventName, $event); |
||
56 | } |
||
57 | |||
58 | return parent::dispatch($eventName, $event); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param AbstractEvent $event |
||
63 | */ |
||
64 | 4 | public function dispatchEvent(AbstractEvent $event) |
|
72 | |||
73 | /** |
||
74 | * @param AbstractEvent $event |
||
75 | * @param int|null $timestamp |
||
76 | */ |
||
77 | 2 | public function dispatchInBackground(AbstractEvent $event, int $timestamp = 0) |
|
87 | |||
88 | /** |
||
89 | * @param AbstractEvent $event |
||
90 | */ |
||
91 | 1 | private function dispatchAsWebsocketEvent(AbstractEvent $event) |
|
97 | } |
||
98 |