Passed
Push — master ( 4c6bc6...f797a9 )
by Roeland
17:19 queued 03:27
created
lib/private/EventDispatcher/SymfonyAdapter.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -43,171 +43,171 @@
 block discarded – undo
43 43
  */
44 44
 class SymfonyAdapter implements EventDispatcherInterface {
45 45
 
46
-	/** @var EventDispatcher */
47
-	private $eventDispatcher;
48
-	/** @var ILogger */
49
-	private $logger;
50
-
51
-	/**
52
-	 * @deprecated 20.0.0
53
-	 */
54
-	public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) {
55
-		$this->eventDispatcher = $eventDispatcher;
56
-		$this->logger = $logger;
57
-	}
58
-
59
-	private static function detectEventAndName($a, $b) {
60
-		if (is_object($a) && (is_string($b) || $b === null)) {
61
-			// a is the event, the other one is the optional name
62
-			return [$a, $b];
63
-		}
64
-		if (is_object($b) && (is_string($a) || $a === null)) {
65
-			// b is the event, the other one is the optional name
66
-			return [$b, $a];
67
-		}
68
-		if (is_string($a) && $b === null) {
69
-			// a is a payload-less event
70
-			return [null, $a];
71
-		}
72
-		if (is_string($b) && $a === null) {
73
-			// b is a payload-less event
74
-			return [null, $b];
75
-		}
76
-
77
-		// Anything else we can't detect
78
-		return [$a, $b];
79
-	}
80
-
81
-	/**
82
-	 * Dispatches an event to all registered listeners.
83
-	 *
84
-	 * @param string $eventName The name of the event to dispatch. The name of
85
-	 *                              the event is the name of the method that is
86
-	 *                              invoked on listeners.
87
-	 * @param Event|null $event The event to pass to the event handlers/listeners
88
-	 *                              If not supplied, an empty Event instance is created
89
-	 *
90
-	 * @return object the emitted event
91
-	 * @deprecated 20.0.0
92
-	 */
93
-	public function dispatch($eventName, $event = null): object {
94
-		[$event, $eventName] = self::detectEventAndName($event, $eventName);
95
-
96
-		// type hinting is not possible, due to usage of GenericEvent
97
-		if ($event instanceof Event && $eventName === null) {
98
-			$this->eventDispatcher->dispatchTyped($event);
99
-			return $event;
100
-		}
101
-		if ($event instanceof Event) {
102
-			$this->eventDispatcher->dispatch($eventName, $event);
103
-			return $event;
104
-		}
105
-
106
-		if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
107
-			$newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
108
-		} else {
109
-			$newEvent = $event;
110
-
111
-			// Legacy event
112
-			$this->logger->info(
113
-				'Deprecated event type for {name}: {class}',
114
-				['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
115
-			);
116
-		}
117
-
118
-		// Event with no payload (object) need special handling
119
-		if ($newEvent === null) {
120
-			$this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName);
121
-			return new Event();
122
-		}
123
-
124
-		// Flip the argument order for Symfony to prevent a trigger_error
125
-		return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName);
126
-	}
127
-
128
-	/**
129
-	 * Adds an event listener that listens on the specified events.
130
-	 *
131
-	 * @param string $eventName The event to listen on
132
-	 * @param callable $listener The listener
133
-	 * @param int $priority The higher this value, the earlier an event
134
-	 *                            listener will be triggered in the chain (defaults to 0)
135
-	 * @deprecated 20.0.0
136
-	 */
137
-	public function addListener($eventName, $listener, $priority = 0) {
138
-		if (is_callable($listener)) {
139
-			$this->eventDispatcher->addListener($eventName, $listener, $priority);
140
-		} else {
141
-			// Legacy listener
142
-			$this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority);
143
-		}
144
-	}
145
-
146
-	/**
147
-	 * Adds an event subscriber.
148
-	 *
149
-	 * The subscriber is asked for all the events it is
150
-	 * interested in and added as a listener for these events.
151
-	 * @deprecated 20.0.0
152
-	 */
153
-	public function addSubscriber(EventSubscriberInterface $subscriber) {
154
-		$this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber);
155
-	}
156
-
157
-	/**
158
-	 * Removes an event listener from the specified events.
159
-	 *
160
-	 * @param string $eventName The event to remove a listener from
161
-	 * @param callable $listener The listener to remove
162
-	 * @deprecated 20.0.0
163
-	 */
164
-	public function removeListener($eventName, $listener) {
165
-		$this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener);
166
-	}
167
-
168
-	/**
169
-	 * @deprecated 20.0.0
170
-	 */
171
-	public function removeSubscriber(EventSubscriberInterface $subscriber) {
172
-		$this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber);
173
-	}
174
-
175
-	/**
176
-	 * Gets the listeners of a specific event or all listeners sorted by descending priority.
177
-	 *
178
-	 * @param string|null $eventName The name of the event
179
-	 *
180
-	 * @return array The event listeners for the specified event, or all event listeners by event name
181
-	 * @deprecated 20.0.0
182
-	 */
183
-	public function getListeners($eventName = null) {
184
-		return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName);
185
-	}
186
-
187
-	/**
188
-	 * Gets the listener priority for a specific event.
189
-	 *
190
-	 * Returns null if the event or the listener does not exist.
191
-	 *
192
-	 * @param string $eventName The name of the event
193
-	 * @param callable $listener The listener
194
-	 *
195
-	 * @return int|null The event listener priority
196
-	 * @deprecated 20.0.0
197
-	 */
198
-	public function getListenerPriority($eventName, $listener) {
199
-		return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener);
200
-	}
201
-
202
-	/**
203
-	 * Checks whether an event has any registered listeners.
204
-	 *
205
-	 * @param string|null $eventName The name of the event
206
-	 *
207
-	 * @return bool true if the specified event has any listeners, false otherwise
208
-	 * @deprecated 20.0.0
209
-	 */
210
-	public function hasListeners($eventName = null) {
211
-		return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName);
212
-	}
46
+    /** @var EventDispatcher */
47
+    private $eventDispatcher;
48
+    /** @var ILogger */
49
+    private $logger;
50
+
51
+    /**
52
+     * @deprecated 20.0.0
53
+     */
54
+    public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) {
55
+        $this->eventDispatcher = $eventDispatcher;
56
+        $this->logger = $logger;
57
+    }
58
+
59
+    private static function detectEventAndName($a, $b) {
60
+        if (is_object($a) && (is_string($b) || $b === null)) {
61
+            // a is the event, the other one is the optional name
62
+            return [$a, $b];
63
+        }
64
+        if (is_object($b) && (is_string($a) || $a === null)) {
65
+            // b is the event, the other one is the optional name
66
+            return [$b, $a];
67
+        }
68
+        if (is_string($a) && $b === null) {
69
+            // a is a payload-less event
70
+            return [null, $a];
71
+        }
72
+        if (is_string($b) && $a === null) {
73
+            // b is a payload-less event
74
+            return [null, $b];
75
+        }
76
+
77
+        // Anything else we can't detect
78
+        return [$a, $b];
79
+    }
80
+
81
+    /**
82
+     * Dispatches an event to all registered listeners.
83
+     *
84
+     * @param string $eventName The name of the event to dispatch. The name of
85
+     *                              the event is the name of the method that is
86
+     *                              invoked on listeners.
87
+     * @param Event|null $event The event to pass to the event handlers/listeners
88
+     *                              If not supplied, an empty Event instance is created
89
+     *
90
+     * @return object the emitted event
91
+     * @deprecated 20.0.0
92
+     */
93
+    public function dispatch($eventName, $event = null): object {
94
+        [$event, $eventName] = self::detectEventAndName($event, $eventName);
95
+
96
+        // type hinting is not possible, due to usage of GenericEvent
97
+        if ($event instanceof Event && $eventName === null) {
98
+            $this->eventDispatcher->dispatchTyped($event);
99
+            return $event;
100
+        }
101
+        if ($event instanceof Event) {
102
+            $this->eventDispatcher->dispatch($eventName, $event);
103
+            return $event;
104
+        }
105
+
106
+        if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
107
+            $newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
108
+        } else {
109
+            $newEvent = $event;
110
+
111
+            // Legacy event
112
+            $this->logger->info(
113
+                'Deprecated event type for {name}: {class}',
114
+                ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
115
+            );
116
+        }
117
+
118
+        // Event with no payload (object) need special handling
119
+        if ($newEvent === null) {
120
+            $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName);
121
+            return new Event();
122
+        }
123
+
124
+        // Flip the argument order for Symfony to prevent a trigger_error
125
+        return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName);
126
+    }
127
+
128
+    /**
129
+     * Adds an event listener that listens on the specified events.
130
+     *
131
+     * @param string $eventName The event to listen on
132
+     * @param callable $listener The listener
133
+     * @param int $priority The higher this value, the earlier an event
134
+     *                            listener will be triggered in the chain (defaults to 0)
135
+     * @deprecated 20.0.0
136
+     */
137
+    public function addListener($eventName, $listener, $priority = 0) {
138
+        if (is_callable($listener)) {
139
+            $this->eventDispatcher->addListener($eventName, $listener, $priority);
140
+        } else {
141
+            // Legacy listener
142
+            $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority);
143
+        }
144
+    }
145
+
146
+    /**
147
+     * Adds an event subscriber.
148
+     *
149
+     * The subscriber is asked for all the events it is
150
+     * interested in and added as a listener for these events.
151
+     * @deprecated 20.0.0
152
+     */
153
+    public function addSubscriber(EventSubscriberInterface $subscriber) {
154
+        $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber);
155
+    }
156
+
157
+    /**
158
+     * Removes an event listener from the specified events.
159
+     *
160
+     * @param string $eventName The event to remove a listener from
161
+     * @param callable $listener The listener to remove
162
+     * @deprecated 20.0.0
163
+     */
164
+    public function removeListener($eventName, $listener) {
165
+        $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener);
166
+    }
167
+
168
+    /**
169
+     * @deprecated 20.0.0
170
+     */
171
+    public function removeSubscriber(EventSubscriberInterface $subscriber) {
172
+        $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber);
173
+    }
174
+
175
+    /**
176
+     * Gets the listeners of a specific event or all listeners sorted by descending priority.
177
+     *
178
+     * @param string|null $eventName The name of the event
179
+     *
180
+     * @return array The event listeners for the specified event, or all event listeners by event name
181
+     * @deprecated 20.0.0
182
+     */
183
+    public function getListeners($eventName = null) {
184
+        return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName);
185
+    }
186
+
187
+    /**
188
+     * Gets the listener priority for a specific event.
189
+     *
190
+     * Returns null if the event or the listener does not exist.
191
+     *
192
+     * @param string $eventName The name of the event
193
+     * @param callable $listener The listener
194
+     *
195
+     * @return int|null The event listener priority
196
+     * @deprecated 20.0.0
197
+     */
198
+    public function getListenerPriority($eventName, $listener) {
199
+        return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener);
200
+    }
201
+
202
+    /**
203
+     * Checks whether an event has any registered listeners.
204
+     *
205
+     * @param string|null $eventName The name of the event
206
+     *
207
+     * @return bool true if the specified event has any listeners, false otherwise
208
+     * @deprecated 20.0.0
209
+     */
210
+    public function hasListeners($eventName = null) {
211
+        return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName);
212
+    }
213 213
 }
Please login to merge, or discard this patch.