bug #18426 [EventDispatcher] Try first if the event is Stopped (lyrixx)
This PR was merged into the 2.3 branch.
Discussion
----------
[EventDispatcher] Try first if the event is Stopped
| Q | A
| ------------- | ---
| Branch? | 2.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
If you trigger 2 events with the same instance of Event and if a listener in the first dispatch stop the propagation, then the very first listener of the second dispatch is called. It should not IMHO.
Commits
-------
a30e166
[EventDispatcher] Try first if the event is Stopped
This commit is contained in:
commit
18ddc88fb0
@ -155,10 +155,10 @@ class EventDispatcher implements EventDispatcherInterface
|
|||||||
protected function doDispatch($listeners, $eventName, Event $event)
|
protected function doDispatch($listeners, $eventName, Event $event)
|
||||||
{
|
{
|
||||||
foreach ($listeners as $listener) {
|
foreach ($listeners as $listener) {
|
||||||
call_user_func($listener, $event);
|
|
||||||
if ($event->isPropagationStopped()) {
|
if ($event->isPropagationStopped()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
call_user_func($listener, $event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +136,10 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
|
|||||||
$event = new Event();
|
$event = new Event();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== $this->logger && $event->isPropagationStopped()) {
|
||||||
|
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
|
||||||
|
}
|
||||||
|
|
||||||
$eventId = ++$this->lastEventId;
|
$eventId = ++$this->lastEventId;
|
||||||
|
|
||||||
$this->preDispatch($eventName, $eventId, $event);
|
$this->preDispatch($eventName, $eventId, $event);
|
||||||
|
Reference in New Issue
Block a user