Skip to content

Commit bf2ff76

Browse files
committed
minor #20196 [SecurityBundle] Cache contexts per request in FirewallMap (chalasr)
This PR was merged into the 3.2-dev branch. Discussion ---------- [SecurityBundle] Cache contexts per request in FirewallMap | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19819 (comment) | License | MIT | Doc PR | n/a From @HeahDude in #19819 (comment), I propose to store and retrieve `Context` objects per `Request` using `SplObjectStorage`. At the moment, contexts are consumed by the `Symfony\Components\Security\Http\Firewall` class only, but they could be indirectly by end users if #19490 and/or #19819 come to be merged. Commits ------- ffacec1 [SecurityBundle] Cache contexts per request in FirewallMap
2 parents 4cc2424 + ffacec1 commit bf2ff76

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@ class FirewallMap implements FirewallMapInterface
2626
{
2727
protected $container;
2828
protected $map;
29+
private $contexts;
2930

3031
public function __construct(ContainerInterface $container, array $map)
3132
{
3233
$this->container = $container;
3334
$this->map = $map;
35+
$this->contexts = new \SplObjectStorage();
3436
}
3537

3638
public function getListeners(Request $request)
3739
{
40+
if ($this->contexts->contains($request)) {
41+
return $this->contexts[$request];
42+
}
43+
3844
foreach ($this->map as $contextId => $requestMatcher) {
3945
if (null === $requestMatcher || $requestMatcher->matches($request)) {
40-
return $this->container->get($contextId)->getContext();
46+
return $this->contexts[$request] = $this->container->get($contextId)->getContext();
4147
}
4248
}
4349

0 commit comments

Comments
 (0)