bug #31991 [EventDispatcher] collect called listeners information only once (xabbuh)

This PR was merged into the 4.3 branch.

Discussion
----------

[EventDispatcher] collect called listeners information only once

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31970
| License       | MIT
| Doc PR        |

Commits
-------

284262a219 collect called listeners information only once
This commit is contained in:
Fabien Potencier 2019-06-11 20:36:39 +02:00
commit ac1a660130

View File

@ -224,22 +224,22 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
}
$hash = 1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) ? spl_object_hash($request) : null;
$calledListeners = [];
if (null !== $this->callStack) {
foreach ($this->callStack as $calledListener) {
list(, $requestHash) = $this->callStack->getInfo();
if (null === $hash || $hash === $requestHash) {
$calledListeners[] = $calledListener->getWrappedListener();
}
}
}
$notCalled = [];
foreach ($allListeners as $eventName => $listeners) {
foreach ($listeners as $listener) {
$called = false;
if (null !== $this->callStack) {
foreach ($this->callStack as $calledListener) {
list(, $requestHash) = $this->callStack->getInfo();
if ((null === $hash || $hash === $requestHash) && $calledListener->getWrappedListener() === $listener) {
$called = true;
break;
}
}
}
if (!$called) {
if (!\in_array($listener, $calledListeners, true)) {
if (!$listener instanceof WrappedListener) {
$listener = new WrappedListener($listener, null, $this->stopwatch, $this);
}