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 | 8 | public function __construct(ContainerInterface $container) |
|
34 | |||
35 | /** |
||
36 | * @param EventDispatcherInterface $dispatcher |
||
37 | */ |
||
38 | public function addCatchall(EventDispatcherInterface $dispatcher) |
||
42 | |||
43 | /** |
||
44 | * @param string $eventName |
||
45 | * @param Event $event |
||
46 | * @return Event |
||
47 | */ |
||
48 | 2 | public function dispatch($eventName, Event $event = null) |
|
49 | { |
||
50 | 2 | if (empty($event)) { |
|
51 | 1 | throw new RuntimeException('You have to pass an Event into EventDispatcher::dispatch'); |
|
52 | } |
||
53 | |||
54 | 1 | foreach ($this->catchall as $dispatcher) { |
|
55 | $dispatcher->dispatch($eventName, $event); |
||
56 | } |
||
57 | |||
58 | 1 | return parent::dispatch($eventName, $event); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param AbstractEvent $event |
||
63 | */ |
||
64 | 4 | public function dispatchEvent(AbstractEvent $event) |
|
65 | { |
||
66 | 4 | $this->dispatch($event->eventName, $event); |
|
67 | 4 | if ($event instanceof PushViaWebsocket) { |
|
68 | /** @var AbstractEvent $event */ |
||
69 | 1 | $this->dispatchAsWebsocketEvent($event); |
|
70 | } |
||
71 | 4 | } |
|
72 | |||
73 | /** |
||
74 | * @param AbstractEvent $event |
||
75 | */ |
||
76 | 1 | public function dispatchAsWebsocketEvent(AbstractEvent $event) |
|
82 | |||
83 | /** |
||
84 | * @param AbstractEvent $event |
||
85 | * @param integer|null $timestamp |
||
86 | */ |
||
87 | 2 | public function dispatchInBackground(AbstractEvent $event, $timestamp = 0) |
|
97 | } |
||
98 |