[EventDispatcher] Try first if the event is Stopped

This commit is contained in:
Grégoire Pineau 2016-04-03 23:45:45 +02:00
parent 131436525f
commit a30e1662d8
2 changed files with 5 additions and 1 deletions

View File

@ -155,10 +155,10 @@ class EventDispatcher implements EventDispatcherInterface
protected function doDispatch($listeners, $eventName, Event $event)
{
foreach ($listeners as $listener) {
call_user_func($listener, $event);
if ($event->isPropagationStopped()) {
break;
}
call_user_func($listener, $event);
}
}

View File

@ -136,6 +136,10 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
$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;
$this->preDispatch($eventName, $eventId, $event);