Skip to content

Commit

Permalink
minor #20196 [SecurityBundle] Cache contexts per request in FirewallM…
Browse files Browse the repository at this point in the history
…ap (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
  • Loading branch information
fabpot committed Oct 12, 2016
2 parents 4cc2424 + ffacec1 commit bf2ff76
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit bf2ff76

Please sign in to comment.