Permalink
Browse files

feature #21451 [SecurityBundle] Lazy load request matchers in Firewal…

…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...
2 parents 00ab4b3 + 5b72cf6 commit 991e062a9182f688e206966d8daa8a9c1c4ffc7d @fabpot fabpot committed Jan 31, 2017
View
@@ -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
@@ -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
---------------
@@ -1,6 +1,11 @@
CHANGELOG
=========
+3.3.0
+-----
+
+ * Deprecated the `FirewallMap::$map` and `$container` properties.
+
3.2.0
-----
@@ -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;
@@ -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) {
@@ -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">
@@ -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;
@@ -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']);
@@ -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();

0 comments on commit 991e062

Please sign in to comment.