Skip to content

Commit 2c863c6

Browse files
author
Robin Chalas
committed
minor symfony#28224 [Security\Http] Restore laziness of listener iterator (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Security\Http] Restore laziness of listener iterator | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no (never released) | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Alternative to symfony#28223 Restores laziness that I broke in merge commit symfony@2dedacb#diff-31ca8a8ce837591218082b00363149fc Commits ------- 2ebc75b [Security\Http] Restore laziness of listener iterator
2 parents d351daa + 2ebc75b commit 2c863c6

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/Symfony/Component/Security/Http/Firewall.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,38 @@ public function onKernelRequest(GetResponseEvent $event)
5050
// register listeners for this firewall
5151
$listeners = $this->map->getListeners($event->getRequest());
5252

53-
$accessListener = null;
54-
$authenticationListeners = array();
55-
56-
foreach ($listeners[0] as $listener) {
57-
if ($listener instanceof AccessListener) {
58-
$accessListener = $listener;
59-
} else {
60-
$authenticationListeners[] = $listener;
61-
}
62-
}
53+
$authenticationListeners = $listeners[0];
54+
$exceptionListener = $listeners[1];
55+
$logoutListener = isset($listeners[2]) ? $listeners[2] : null;
6356

64-
if (null !== $exceptionListener = $listeners[1]) {
57+
if (null !== $exceptionListener) {
6558
$this->exceptionListeners[$event->getRequest()] = $exceptionListener;
6659
$exceptionListener->register($this->dispatcher);
6760
}
6861

69-
if (null !== $logoutListener = isset($listeners[2]) ? $listeners[2] : null) {
70-
$authenticationListeners[] = $logoutListener;
71-
}
62+
$authenticationListeners = function () use ($authenticationListeners, $logoutListener) {
63+
$accessListener = null;
7264

73-
if (null !== $accessListener) {
74-
$authenticationListeners[] = $accessListener;
75-
}
65+
foreach ($authenticationListeners as $listener) {
66+
if ($listener instanceof AccessListener) {
67+
$accessListener = $listener;
68+
69+
continue;
70+
}
71+
72+
yield $listener;
73+
}
74+
75+
if (null !== $logoutListener) {
76+
yield $logoutListener;
77+
}
78+
79+
if (null !== $accessListener) {
80+
yield $accessListener;
81+
}
82+
};
7683

77-
$this->handleRequest($event, $authenticationListeners);
84+
$this->handleRequest($event, $authenticationListeners());
7885
}
7986

8087
public function onKernelFinishRequest(FinishRequestEvent $event)

0 commit comments

Comments
 (0)