FirewallMap.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Http\FirewallMapInterface;
  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 implements FirewallMapInterface
  22. {
  23. protected $container;
  24. protected $map;
  25. public function __construct(ContainerInterface $container, array $map)
  26. {
  27. $this->container = $container;
  28. $this->map = $map;
  29. }
  30. public function getListeners(Request $request)
  31. {
  32. foreach ($this->map as $contextId => $requestMatcher) {
  33. if (null === $requestMatcher || $requestMatcher->matches($request)) {
  34. return $this->container->get($contextId)->getContext();
  35. }
  36. }
  37. return array(array(), null, null);
  38. }
  39. }