summaryrefslogtreecommitdiffstats
path: root/lib/private/EventDispatcher
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-12-29 20:43:01 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-01-05 16:00:42 +0100
commit85454ac4565aa2182895080c8159580f535b33f1 (patch)
tree66343f3293559715324972c53446c87c6fbba3bb /lib/private/EventDispatcher
parent9b9c1aa7fd643747cd423d40c9c82ffa74e9e452 (diff)
downloadnextcloud-server-85454ac4565aa2182895080c8159580f535b33f1.tar.gz
nextcloud-server-85454ac4565aa2182895080c8159580f535b33f1.zip
Use the Symfony dispatcher correctly
* Event object as first arg (otherwise there is a notice in the logs) * `dispatch` MUST return the event object Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/EventDispatcher')
-rw-r--r--lib/private/EventDispatcher/SymfonyAdapter.php36
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/private/EventDispatcher/SymfonyAdapter.php b/lib/private/EventDispatcher/SymfonyAdapter.php
index 9389e725405..b1e5aa86049 100644
--- a/lib/private/EventDispatcher/SymfonyAdapter.php
+++ b/lib/private/EventDispatcher/SymfonyAdapter.php
@@ -63,27 +63,35 @@ class SymfonyAdapter implements EventDispatcherInterface {
* @param Event|null $event The event to pass to the event handlers/listeners
* If not supplied, an empty Event instance is created
*
- * @return void
+ * @return object the emitted event
* @deprecated 20.0.0
*/
- public function dispatch($eventName, $event = null) {
+ public function dispatch($eventName, $event = null): object {
// type hinting is not possible, due to usage of GenericEvent
if ($event instanceof Event) {
$this->eventDispatcher->dispatch($eventName, $event);
+ return $event;
+ }
+
+ if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
+ $newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
} else {
- if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
- $newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
- } else {
- $newEvent = $event;
-
- // Legacy event
- $this->logger->info(
- 'Deprecated event type for {name}: {class}',
- ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
- );
- }
- $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $newEvent);
+ $newEvent = $event;
+
+ // Legacy event
+ $this->logger->info(
+ 'Deprecated event type for {name}: {class}',
+ ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
+ );
}
+
+ // Event with no payload (object) need special handling
+ if ($newEvent === null) {
+ return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName);
+ }
+
+ // Flip the argument order for Symfony to prevent a trigger_error
+ return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName);
}
/**