vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php line 135

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\SecurityBundle\Security;
  11. use Psr\Container\ContainerInterface;
  12. use Symfony\Component\Security\Http\FirewallMapInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. /**
  15.  * This is a lazy-loading firewall map implementation.
  16.  *
  17.  * Listeners will only be initialized if we really need them.
  18.  *
  19.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  20.  */
  21. class FirewallMap extends _FirewallMap implements FirewallMapInterface
  22. {
  23.     /**
  24.      * @deprecated since version 3.3, to be removed in 4.0 alongside with magic methods below
  25.      */
  26.     private $container;
  27.     /**
  28.      * @deprecated since version 3.3, to be removed in 4.0 alongside with magic methods below
  29.      */
  30.     private $map;
  31.     public function __construct(ContainerInterface $container$map)
  32.     {
  33.         parent::__construct($container$map);
  34.         $this->container $container;
  35.         $this->map $map;
  36.     }
  37.     /**
  38.      * @internal
  39.      */
  40.     public function __get($name)
  41.     {
  42.         if ('map' === $name || 'container' === $name) {
  43.             @trigger_error(sprintf('Using the "%s::$%s" property is deprecated since Symfony 3.3 as it will be removed/private in 4.0.'__CLASS__$name), E_USER_DEPRECATED);
  44.             if ('map' === $name && $this->map instanceof \Traversable) {
  45.                 $this->map iterator_to_array($this->map);
  46.             }
  47.         }
  48.         return $this->$name;
  49.     }
  50.     /**
  51.      * @internal
  52.      */
  53.     public function __set($name$value)
  54.     {
  55.         if ('map' === $name || 'container' === $name) {
  56.             @trigger_error(sprintf('Using the "%s::$%s" property is deprecated since Symfony 3.3 as it will be removed/private in 4.0.'__CLASS__$name), E_USER_DEPRECATED);
  57.             $set = \Closure::bind(function ($name$value) { $this->$name $value; }, $thisparent::class);
  58.             $set($name$value);
  59.         }
  60.         $this->$name $value;
  61.     }
  62.     /**
  63.      * @internal
  64.      */
  65.     public function __isset($name)
  66.     {
  67.         if ('map' === $name || 'container' === $name) {
  68.             @trigger_error(sprintf('Using the "%s::$%s" property is deprecated since Symfony 3.3 as it will be removed/private in 4.0.'__CLASS__$name), E_USER_DEPRECATED);
  69.         }
  70.         return isset($this->$name);
  71.     }
  72.     /**
  73.      * @internal
  74.      */
  75.     public function __unset($name)
  76.     {
  77.         if ('map' === $name || 'container' === $name) {
  78.             @trigger_error(sprintf('Using the "%s::$%s" property is deprecated since Symfony 3.3 as it will be removed/private in 4.0.'__CLASS__$name), E_USER_DEPRECATED);
  79.             $unset = \Closure::bind(function ($name) { unset($this->$name); }, $thisparent::class);
  80.             $unset($name);
  81.         }
  82.         unset($this->$name);
  83.     }
  84. }
  85. /**
  86.  * @internal to be removed in 4.0
  87.  */
  88. class _FirewallMap
  89. {
  90.     private $container;
  91.     private $map;
  92.     private $contexts;
  93.     public function __construct(ContainerInterface $container$map)
  94.     {
  95.         $this->container $container;
  96.         $this->map $map;
  97.         $this->contexts = new \SplObjectStorage();
  98.     }
  99.     public function getListeners(Request $request)
  100.     {
  101.         $context $this->getFirewallContext($request);
  102.         if (null === $context) {
  103.             return array(array(), null);
  104.         }
  105.         return array($context->getListeners(), $context->getExceptionListener());
  106.     }
  107.     /**
  108.      * @return FirewallConfig|null
  109.      */
  110.     public function getFirewallConfig(Request $request)
  111.     {
  112.         $context $this->getFirewallContext($request);
  113.         if (null === $context) {
  114.             return;
  115.         }
  116.         return $context->getConfig();
  117.     }
  118.     /**
  119.      * @return FirewallContext
  120.      */
  121.     private function getFirewallContext(Request $request)
  122.     {
  123.         if ($request->attributes->has('_firewall_context')) {
  124.             $storedContextId $request->attributes->get('_firewall_context');
  125.             foreach ($this->map as $contextId => $requestMatcher) {
  126.                 if ($contextId === $storedContextId) {
  127.                     return $this->container->get($contextId);
  128.                 }
  129.             }
  130.             $request->attributes->remove('_firewall_context');
  131.         }
  132.         foreach ($this->map as $contextId => $requestMatcher) {
  133.             if (null === $requestMatcher || $requestMatcher->matches($request)) {
  134.                 $request->attributes->set('_firewall_context'$contextId);
  135.                 return $this->container->get($contextId);
  136.             }
  137.         }
  138.     }
  139. }