AccessMap.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Component\Security\Http;
  11. use Symfony\Component\HttpFoundation\RequestMatcherInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. /**
  14. * AccessMap allows configuration of different access control rules for
  15. * specific parts of the website.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class AccessMap implements AccessMapInterface
  20. {
  21. private $map = array();
  22. /**
  23. * Constructor.
  24. *
  25. * @param RequestMatcherInterface $requestMatcher A RequestMatcherInterface instance
  26. * @param array $roles An array of roles needed to access the resource
  27. * @param string|null $channel The channel to enforce (http, https, or null)
  28. */
  29. public function add(RequestMatcherInterface $requestMatcher, array $roles = array(), $channel = null)
  30. {
  31. $this->map[] = array($requestMatcher, $roles, $channel);
  32. }
  33. public function getPatterns(Request $request)
  34. {
  35. foreach ($this->map as $elements) {
  36. if (null === $elements[0] || $elements[0]->matches($request)) {
  37. return array($elements[1], $elements[2]);
  38. }
  39. }
  40. return array(null, null);
  41. }
  42. }