bug #30794 [EventDispatcher] Fix BC/FC layer (chalasr)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[EventDispatcher] Fix BC/FC layer

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Fixes
> TypeError: Argument 3 passed to Symfony\Component\EventDispatcher\EventDispatcher::doDispatch() must be an instance of Symfony\Component\EventDispatcher\Event

Spotted in https://github.com/lexik/LexikJWTAuthenticationBundle/pull/637

Commits
-------

caa0aded89 [EventDispatcher] Fix BC layer
This commit is contained in:
Fabien Potencier 2019-03-31 18:36:43 +02:00
commit 8c2ade9173

View File

@ -230,7 +230,20 @@ class EventDispatcher implements EventDispatcherInterface
*/
protected function callListeners(iterable $listeners, string $eventName, $event)
{
$this->doDispatch($listeners, $eventName, $event);
if ($event instanceof Event) {
$this->doDispatch($listeners, $eventName, $event);
return;
}
$stoppable = $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;
foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
break;
}
$listener($event, $eventName, $this);
}
}
/**
@ -238,10 +251,8 @@ class EventDispatcher implements EventDispatcherInterface
*/
protected function doDispatch($listeners, $eventName, Event $event)
{
$stoppable = $event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;
foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
if ($event->isPropagationStopped()) {
break;
}
$listener($event, $eventName, $this);