Skip to content

Commit

Permalink
feature #21451 [SecurityBundle] Lazy load request matchers in Firewal…
Browse files Browse the repository at this point in the history
…lMap (chalasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[SecurityBundle] Lazy load request matchers in FirewallMap

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

5b72cf6 [Security] Lazy load request matchers
  • Loading branch information
fabpot committed Jan 31, 2017
2 parents 00ab4b3 + 5b72cf6 commit 991e062
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 8 deletions.
2 changes: 2 additions & 0 deletions UPGRADE-3.3.md
Expand Up @@ -58,6 +58,8 @@ SecurityBundle
* The `FirewallContext::getContext()` method has been deprecated and will be removed in 4.0.
Use the `getListeners()` method instead.

* The `FirewallMap::$map` and `$container` properties have been deprecated and will be removed in 4.0.

TwigBridge
----------

Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Expand Up @@ -164,6 +164,8 @@ SecurityBundle

* The `FirewallContext::getContext()` method has been removed, use the `getListeners()` method instead.

* The `FirewallMap::$map` and `$container` properties have been removed.

HttpFoundation
---------------

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.3.0
-----

* Deprecated the `FirewallMap::$map` and `$container` properties.

3.2.0
-----

Expand Down
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -255,7 +256,7 @@ private function createFirewalls($config, ContainerBuilder $container)

$map[$contextId] = $matcher;
}
$mapDef->replaceArgument(1, $map);
$mapDef->replaceArgument(1, new IteratorArgument($map));

// add authentication providers to authentication manager
$authenticationProviders = array_map(function ($id) {
Expand Down
Expand Up @@ -105,7 +105,7 @@

<service id="security.firewall.map" class="Symfony\Bundle\SecurityBundle\Security\FirewallMap" public="false">
<argument type="service" id="service_container" />
<argument type="collection" />
<argument />
</service>

<service id="security.firewall.context" class="Symfony\Bundle\SecurityBundle\Security\FirewallContext" abstract="true">
Expand Down
89 changes: 85 additions & 4 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Expand Up @@ -22,13 +22,94 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class FirewallMap implements FirewallMapInterface
class FirewallMap extends _FirewallMap implements FirewallMapInterface
{
protected $container;
protected $map;
/**
* @deprecated since version 3.3, to be removed in 4.0 alongside with magic methods below
*/
private $container;

/**
* @deprecated since version 3.3, to be removed in 4.0 alongside with magic methods below
*/
private $map;

public function __construct(ContainerInterface $container, $map)
{
parent::__construct($container, $map);
$this->container = $container;
$this->map = $map;
}

/**
* @internal
*/
public function __get($name)
{
if ('map' === $name || 'container' === $name) {
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);

if ('map' === $name && $this->map instanceof \Traversable) {
$this->map = iterator_to_array($this->map);
}
}

return $this->$name;
}

/**
* @internal
*/
public function __set($name, $value)
{
if ('map' === $name || 'container' === $name) {
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);

$set = \Closure::bind(function ($name, $value) { $this->$name = $value; }, $this, parent::class);
$set($name, $value);
}

$this->$name = $value;
}

/**
* @internal
*/
public function __isset($name)
{
if ('map' === $name || 'container' === $name) {
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);
}

return isset($this->$name);
}

/**
* @internal
*/
public function __unset($name)
{
if ('map' === $name || 'container' === $name) {
@trigger_error(sprintf('Using the "%s::$%s" property is deprecated since version 3.3 as it will be removed/private in 4.0.', __CLASS__, $name), E_USER_DEPRECATED);

$unset = \Closure::bind(function ($name) { unset($this->$name); }, $this, parent::class);
$unset($name);
}

unset($this->$name);
}
}

/**
* @internal to be removed in 4.0
*/
class _FirewallMap
{
private $container;
private $map;
private $contexts;

public function __construct(ContainerInterface $container, array $map)
public function __construct(ContainerInterface $container, $map)
{
$this->container = $container;
$this->map = $map;
Expand Down
Expand Up @@ -68,7 +68,7 @@ public function testFirewalls()
$arguments = $container->getDefinition('security.firewall.map')->getArguments();
$listeners = array();
$configs = array();
foreach (array_keys($arguments[1]) as $contextId) {
foreach (array_keys($arguments[1]->getValues()) as $contextId) {
$contextDef = $container->getDefinition($contextId);
$arguments = $contextDef->getArguments();
$listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']);
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testFirewallRequestMatchers()
$arguments = $container->getDefinition('security.firewall.map')->getArguments();
$matchers = array();

foreach ($arguments[1] as $reference) {
foreach ($arguments[1]->getValues() as $reference) {
if ($reference instanceof Reference) {
$definition = $container->getDefinition((string) $reference);
$matchers[] = $definition->getArguments();
Expand Down

0 comments on commit 991e062

Please sign in to comment.