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