Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18ddc88

Browse files
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
2 parents 41fd14a + a30e166 commit 18ddc88

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
155155
protected function doDispatch($listeners, $eventName, Event $event)
156156
{
157157
foreach ($listeners as $listener) {
158-
call_user_func($listener, $event);
159158
if ($event->isPropagationStopped()) {
160159
break;
161160
}
161+
call_user_func($listener, $event);
162162
}
163163
}
164164

src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public function dispatch($eventName, Event $event = null)
136136
$event = new Event();
137137
}
138138

139+
if (null !== $this->logger && $event->isPropagationStopped()) {
140+
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
141+
}
142+
139143
$eventId = ++$this->lastEventId;
140144

141145
$this->preDispatch($eventName, $eventId, $event);

0 commit comments

Comments
 (0)