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