diff --git a/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php b/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php index dc87681c3751..da79e3c8c292 100644 --- a/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php +++ b/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php @@ -26,18 +26,24 @@ class FirewallMap implements FirewallMapInterface { protected $container; protected $map; + private $contexts; public function __construct(ContainerInterface $container, array $map) { $this->container = $container; $this->map = $map; + $this->contexts = new \SplObjectStorage(); } public function getListeners(Request $request) { + if ($this->contexts->contains($request)) { + return $this->contexts[$request]; + } + foreach ($this->map as $contextId => $requestMatcher) { if (null === $requestMatcher || $requestMatcher->matches($request)) { - return $this->container->get($contextId)->getContext(); + return $this->contexts[$request] = $this->container->get($contextId)->getContext(); } }