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>
This commit is contained in:
parent
9b9c1aa7fd
commit
85454ac456
|
@ -63,14 +63,16 @@ class SymfonyAdapter implements EventDispatcherInterface {
|
||||||
* @param Event|null $event The event to pass to the event handlers/listeners
|
* @param Event|null $event The event to pass to the event handlers/listeners
|
||||||
* If not supplied, an empty Event instance is created
|
* If not supplied, an empty Event instance is created
|
||||||
*
|
*
|
||||||
* @return void
|
* @return object the emitted event
|
||||||
* @deprecated 20.0.0
|
* @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
|
// type hinting is not possible, due to usage of GenericEvent
|
||||||
if ($event instanceof Event) {
|
if ($event instanceof Event) {
|
||||||
$this->eventDispatcher->dispatch($eventName, $event);
|
$this->eventDispatcher->dispatch($eventName, $event);
|
||||||
} else {
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
|
if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
|
||||||
$newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
|
$newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,8 +84,14 @@ class SymfonyAdapter implements EventDispatcherInterface {
|
||||||
['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
|
['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $newEvent);
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue