Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Symfony dispatcher correctly #24892

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions lib/private/EventDispatcher/SymfonyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,35 @@ public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) {
* @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);
}

/**
Expand Down