[Security] Lazy load request matchers

This commit is contained in:
Robin Chalas 2017-01-29 12:38:33 +01:00
parent 2183f98f54
commit 5b72cf6950
No known key found for this signature in database
GPG Key ID: 89672113756EE03B
7 changed files with 99 additions and 8 deletions

View File

@ -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
----------

View File

@ -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
---------------

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
3.3.0
-----
* Deprecated the `FirewallMap::$map` and `$container` properties.
3.2.0
-----

View File

@ -15,6 +15,7 @@ use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityF
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;
@ -255,7 +256,7 @@ class SecurityExtension extends Extension
$map[$contextId] = $matcher;
}
$mapDef->replaceArgument(1, $map);
$mapDef->replaceArgument(1, new IteratorArgument($map));
// add authentication providers to authentication manager
$authenticationProviders = array_map(function ($id) {

View File

@ -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">

View File

@ -22,13 +22,94 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @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;

View File

@ -68,7 +68,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
$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']);
@ -180,7 +180,7 @@ abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase
$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();