From 2ebc75b9a18551b0eb5f2ae5bfd27c8d25094150 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 18 Aug 2018 22:38:48 +0200 Subject: [PATCH] [Security\Http] Restore laziness of listener iterator --- .../Component/Security/Http/Firewall.php | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index b9d83b49cd..a0a2aa8411 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -50,31 +50,38 @@ class Firewall implements EventSubscriberInterface // register listeners for this firewall $listeners = $this->map->getListeners($event->getRequest()); - $accessListener = null; - $authenticationListeners = array(); + $authenticationListeners = $listeners[0]; + $exceptionListener = $listeners[1]; + $logoutListener = isset($listeners[2]) ? $listeners[2] : null; - foreach ($listeners[0] as $listener) { - if ($listener instanceof AccessListener) { - $accessListener = $listener; - } else { - $authenticationListeners[] = $listener; - } - } - - if (null !== $exceptionListener = $listeners[1]) { + if (null !== $exceptionListener) { $this->exceptionListeners[$event->getRequest()] = $exceptionListener; $exceptionListener->register($this->dispatcher); } - if (null !== $logoutListener = isset($listeners[2]) ? $listeners[2] : null) { - $authenticationListeners[] = $logoutListener; - } + $authenticationListeners = function () use ($authenticationListeners, $logoutListener) { + $accessListener = null; - if (null !== $accessListener) { - $authenticationListeners[] = $accessListener; - } + foreach ($authenticationListeners as $listener) { + if ($listener instanceof AccessListener) { + $accessListener = $listener; - $this->handleRequest($event, $authenticationListeners); + continue; + } + + yield $listener; + } + + if (null !== $logoutListener) { + yield $logoutListener; + } + + if (null !== $accessListener) { + yield $accessListener; + } + }; + + $this->handleRequest($event, $authenticationListeners()); } public function onKernelFinishRequest(FinishRequestEvent $event)