@@ -40,134 +40,134 @@ |
||
40 | 40 | */ |
41 | 41 | class SymfonyAdapter implements EventDispatcherInterface { |
42 | 42 | |
43 | - /** @var EventDispatcher */ |
|
44 | - private $eventDispatcher; |
|
45 | - /** @var ILogger */ |
|
46 | - private $logger; |
|
47 | - |
|
48 | - /** |
|
49 | - * @deprecated 20.0.0 |
|
50 | - */ |
|
51 | - public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) { |
|
52 | - $this->eventDispatcher = $eventDispatcher; |
|
53 | - $this->logger = $logger; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Dispatches an event to all registered listeners. |
|
58 | - * |
|
59 | - * @param string $eventName The name of the event to dispatch. The name of |
|
60 | - * the event is the name of the method that is |
|
61 | - * invoked on listeners. |
|
62 | - * @param Event|null $event The event to pass to the event handlers/listeners |
|
63 | - * If not supplied, an empty Event instance is created |
|
64 | - * |
|
65 | - * @return void |
|
66 | - * @deprecated 20.0.0 |
|
67 | - */ |
|
68 | - public function dispatch($eventName, $event = null) { |
|
69 | - // type hinting is not possible, due to usage of GenericEvent |
|
70 | - if ($event instanceof Event) { |
|
71 | - $this->eventDispatcher->dispatch($eventName, $event); |
|
72 | - } else { |
|
73 | - if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) { |
|
74 | - $newEvent = new GenericEventWrapper($this->logger, $eventName, $event); |
|
75 | - } else { |
|
76 | - $newEvent = $event; |
|
77 | - |
|
78 | - // Legacy event |
|
79 | - $this->logger->info( |
|
80 | - 'Deprecated event type for {name}: {class}', |
|
81 | - ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null'] |
|
82 | - ); |
|
83 | - } |
|
84 | - $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $newEvent); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Adds an event listener that listens on the specified events. |
|
90 | - * |
|
91 | - * @param string $eventName The event to listen on |
|
92 | - * @param callable $listener The listener |
|
93 | - * @param int $priority The higher this value, the earlier an event |
|
94 | - * listener will be triggered in the chain (defaults to 0) |
|
95 | - * @deprecated 20.0.0 |
|
96 | - */ |
|
97 | - public function addListener($eventName, $listener, $priority = 0) { |
|
98 | - if (is_callable($listener)) { |
|
99 | - $this->eventDispatcher->addListener($eventName, $listener, $priority); |
|
100 | - } else { |
|
101 | - // Legacy listener |
|
102 | - $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Adds an event subscriber. |
|
108 | - * |
|
109 | - * The subscriber is asked for all the events it is |
|
110 | - * interested in and added as a listener for these events. |
|
111 | - * @deprecated 20.0.0 |
|
112 | - */ |
|
113 | - public function addSubscriber(EventSubscriberInterface $subscriber) { |
|
114 | - $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Removes an event listener from the specified events. |
|
119 | - * |
|
120 | - * @param string $eventName The event to remove a listener from |
|
121 | - * @param callable $listener The listener to remove |
|
122 | - * @deprecated 20.0.0 |
|
123 | - */ |
|
124 | - public function removeListener($eventName, $listener) { |
|
125 | - $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @deprecated 20.0.0 |
|
130 | - */ |
|
131 | - public function removeSubscriber(EventSubscriberInterface $subscriber) { |
|
132 | - $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Gets the listeners of a specific event or all listeners sorted by descending priority. |
|
137 | - * |
|
138 | - * @param string|null $eventName The name of the event |
|
139 | - * |
|
140 | - * @return array The event listeners for the specified event, or all event listeners by event name |
|
141 | - * @deprecated 20.0.0 |
|
142 | - */ |
|
143 | - public function getListeners($eventName = null) { |
|
144 | - return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Gets the listener priority for a specific event. |
|
149 | - * |
|
150 | - * Returns null if the event or the listener does not exist. |
|
151 | - * |
|
152 | - * @param string $eventName The name of the event |
|
153 | - * @param callable $listener The listener |
|
154 | - * |
|
155 | - * @return int|null The event listener priority |
|
156 | - * @deprecated 20.0.0 |
|
157 | - */ |
|
158 | - public function getListenerPriority($eventName, $listener) { |
|
159 | - return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Checks whether an event has any registered listeners. |
|
164 | - * |
|
165 | - * @param string|null $eventName The name of the event |
|
166 | - * |
|
167 | - * @return bool true if the specified event has any listeners, false otherwise |
|
168 | - * @deprecated 20.0.0 |
|
169 | - */ |
|
170 | - public function hasListeners($eventName = null) { |
|
171 | - return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName); |
|
172 | - } |
|
43 | + /** @var EventDispatcher */ |
|
44 | + private $eventDispatcher; |
|
45 | + /** @var ILogger */ |
|
46 | + private $logger; |
|
47 | + |
|
48 | + /** |
|
49 | + * @deprecated 20.0.0 |
|
50 | + */ |
|
51 | + public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) { |
|
52 | + $this->eventDispatcher = $eventDispatcher; |
|
53 | + $this->logger = $logger; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Dispatches an event to all registered listeners. |
|
58 | + * |
|
59 | + * @param string $eventName The name of the event to dispatch. The name of |
|
60 | + * the event is the name of the method that is |
|
61 | + * invoked on listeners. |
|
62 | + * @param Event|null $event The event to pass to the event handlers/listeners |
|
63 | + * If not supplied, an empty Event instance is created |
|
64 | + * |
|
65 | + * @return void |
|
66 | + * @deprecated 20.0.0 |
|
67 | + */ |
|
68 | + public function dispatch($eventName, $event = null) { |
|
69 | + // type hinting is not possible, due to usage of GenericEvent |
|
70 | + if ($event instanceof Event) { |
|
71 | + $this->eventDispatcher->dispatch($eventName, $event); |
|
72 | + } else { |
|
73 | + if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) { |
|
74 | + $newEvent = new GenericEventWrapper($this->logger, $eventName, $event); |
|
75 | + } else { |
|
76 | + $newEvent = $event; |
|
77 | + |
|
78 | + // Legacy event |
|
79 | + $this->logger->info( |
|
80 | + 'Deprecated event type for {name}: {class}', |
|
81 | + ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null'] |
|
82 | + ); |
|
83 | + } |
|
84 | + $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $newEvent); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Adds an event listener that listens on the specified events. |
|
90 | + * |
|
91 | + * @param string $eventName The event to listen on |
|
92 | + * @param callable $listener The listener |
|
93 | + * @param int $priority The higher this value, the earlier an event |
|
94 | + * listener will be triggered in the chain (defaults to 0) |
|
95 | + * @deprecated 20.0.0 |
|
96 | + */ |
|
97 | + public function addListener($eventName, $listener, $priority = 0) { |
|
98 | + if (is_callable($listener)) { |
|
99 | + $this->eventDispatcher->addListener($eventName, $listener, $priority); |
|
100 | + } else { |
|
101 | + // Legacy listener |
|
102 | + $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Adds an event subscriber. |
|
108 | + * |
|
109 | + * The subscriber is asked for all the events it is |
|
110 | + * interested in and added as a listener for these events. |
|
111 | + * @deprecated 20.0.0 |
|
112 | + */ |
|
113 | + public function addSubscriber(EventSubscriberInterface $subscriber) { |
|
114 | + $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Removes an event listener from the specified events. |
|
119 | + * |
|
120 | + * @param string $eventName The event to remove a listener from |
|
121 | + * @param callable $listener The listener to remove |
|
122 | + * @deprecated 20.0.0 |
|
123 | + */ |
|
124 | + public function removeListener($eventName, $listener) { |
|
125 | + $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @deprecated 20.0.0 |
|
130 | + */ |
|
131 | + public function removeSubscriber(EventSubscriberInterface $subscriber) { |
|
132 | + $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Gets the listeners of a specific event or all listeners sorted by descending priority. |
|
137 | + * |
|
138 | + * @param string|null $eventName The name of the event |
|
139 | + * |
|
140 | + * @return array The event listeners for the specified event, or all event listeners by event name |
|
141 | + * @deprecated 20.0.0 |
|
142 | + */ |
|
143 | + public function getListeners($eventName = null) { |
|
144 | + return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Gets the listener priority for a specific event. |
|
149 | + * |
|
150 | + * Returns null if the event or the listener does not exist. |
|
151 | + * |
|
152 | + * @param string $eventName The name of the event |
|
153 | + * @param callable $listener The listener |
|
154 | + * |
|
155 | + * @return int|null The event listener priority |
|
156 | + * @deprecated 20.0.0 |
|
157 | + */ |
|
158 | + public function getListenerPriority($eventName, $listener) { |
|
159 | + return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Checks whether an event has any registered listeners. |
|
164 | + * |
|
165 | + * @param string|null $eventName The name of the event |
|
166 | + * |
|
167 | + * @return bool true if the specified event has any listeners, false otherwise |
|
168 | + * @deprecated 20.0.0 |
|
169 | + */ |
|
170 | + public function hasListeners($eventName = null) { |
|
171 | + return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName); |
|
172 | + } |
|
173 | 173 | } |
@@ -41,68 +41,68 @@ |
||
41 | 41 | |
42 | 42 | class EventDispatcher implements IEventDispatcher { |
43 | 43 | |
44 | - /** @var SymfonyDispatcher */ |
|
45 | - private $dispatcher; |
|
46 | - |
|
47 | - /** @var IContainer */ |
|
48 | - private $container; |
|
49 | - |
|
50 | - /** @var ILogger */ |
|
51 | - private $logger; |
|
52 | - |
|
53 | - public function __construct(SymfonyDispatcher $dispatcher, |
|
54 | - IServerContainer $container, |
|
55 | - ILogger $logger) { |
|
56 | - $this->dispatcher = $dispatcher; |
|
57 | - $this->container = $container; |
|
58 | - $this->logger = $logger; |
|
59 | - } |
|
60 | - |
|
61 | - public function addListener(string $eventName, |
|
62 | - callable $listener, |
|
63 | - int $priority = 0): void { |
|
64 | - $this->dispatcher->addListener($eventName, $listener, $priority); |
|
65 | - } |
|
66 | - |
|
67 | - public function removeListener(string $eventName, |
|
68 | - callable $listener): void { |
|
69 | - $this->dispatcher->removeListener($eventName, $listener); |
|
70 | - } |
|
71 | - |
|
72 | - public function addServiceListener(string $eventName, |
|
73 | - string $className, |
|
74 | - int $priority = 0): void { |
|
75 | - $listener = new ServiceEventListener( |
|
76 | - $this->container, |
|
77 | - $className, |
|
78 | - $this->logger |
|
79 | - ); |
|
80 | - |
|
81 | - $this->addListener($eventName, $listener, $priority); |
|
82 | - } |
|
83 | - |
|
84 | - public function dispatch(string $eventName, |
|
85 | - Event $event): void { |
|
86 | - $this->dispatcher->dispatch($event, $eventName); |
|
87 | - |
|
88 | - if ($event instanceof ABroadcastedEvent && !$event->isPropagationStopped()) { |
|
89 | - // Propagate broadcast |
|
90 | - $this->dispatch( |
|
91 | - IBroadcastEvent::class, |
|
92 | - new BroadcastEvent($event) |
|
93 | - ); |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - public function dispatchTyped(Event $event): void { |
|
98 | - $this->dispatch(get_class($event), $event); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return SymfonyDispatcher |
|
103 | - * @deprecated 20.0.0 |
|
104 | - */ |
|
105 | - public function getSymfonyDispatcher(): SymfonyDispatcher { |
|
106 | - return $this->dispatcher; |
|
107 | - } |
|
44 | + /** @var SymfonyDispatcher */ |
|
45 | + private $dispatcher; |
|
46 | + |
|
47 | + /** @var IContainer */ |
|
48 | + private $container; |
|
49 | + |
|
50 | + /** @var ILogger */ |
|
51 | + private $logger; |
|
52 | + |
|
53 | + public function __construct(SymfonyDispatcher $dispatcher, |
|
54 | + IServerContainer $container, |
|
55 | + ILogger $logger) { |
|
56 | + $this->dispatcher = $dispatcher; |
|
57 | + $this->container = $container; |
|
58 | + $this->logger = $logger; |
|
59 | + } |
|
60 | + |
|
61 | + public function addListener(string $eventName, |
|
62 | + callable $listener, |
|
63 | + int $priority = 0): void { |
|
64 | + $this->dispatcher->addListener($eventName, $listener, $priority); |
|
65 | + } |
|
66 | + |
|
67 | + public function removeListener(string $eventName, |
|
68 | + callable $listener): void { |
|
69 | + $this->dispatcher->removeListener($eventName, $listener); |
|
70 | + } |
|
71 | + |
|
72 | + public function addServiceListener(string $eventName, |
|
73 | + string $className, |
|
74 | + int $priority = 0): void { |
|
75 | + $listener = new ServiceEventListener( |
|
76 | + $this->container, |
|
77 | + $className, |
|
78 | + $this->logger |
|
79 | + ); |
|
80 | + |
|
81 | + $this->addListener($eventName, $listener, $priority); |
|
82 | + } |
|
83 | + |
|
84 | + public function dispatch(string $eventName, |
|
85 | + Event $event): void { |
|
86 | + $this->dispatcher->dispatch($event, $eventName); |
|
87 | + |
|
88 | + if ($event instanceof ABroadcastedEvent && !$event->isPropagationStopped()) { |
|
89 | + // Propagate broadcast |
|
90 | + $this->dispatch( |
|
91 | + IBroadcastEvent::class, |
|
92 | + new BroadcastEvent($event) |
|
93 | + ); |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + public function dispatchTyped(Event $event): void { |
|
98 | + $this->dispatch(get_class($event), $event); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return SymfonyDispatcher |
|
103 | + * @deprecated 20.0.0 |
|
104 | + */ |
|
105 | + public function getSymfonyDispatcher(): SymfonyDispatcher { |
|
106 | + return $this->dispatcher; |
|
107 | + } |
|
108 | 108 | } |