AccessMap.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Request;
  12. use Symfony\Component\HttpFoundation\RequestMatcherInterface;
  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. * @param RequestMatcherInterface $requestMatcher A RequestMatcherInterface instance
  24. * @param array $attributes An array of attributes to pass to the access decision manager (like roles)
  25. * @param string|null $channel The channel to enforce (http, https, or null)
  26. */
  27. public function add(RequestMatcherInterface $requestMatcher, array $attributes = array(), $channel = null)
  28. {
  29. $this->map[] = array($requestMatcher, $attributes, $channel);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getPatterns(Request $request)
  35. {
  36. foreach ($this->map as $elements) {
  37. if (null === $elements[0] || $elements[0]->matches($request)) {
  38. return array($elements[1], $elements[2]);
  39. }
  40. }
  41. return array(null, null);
  42. }
  43. }