AccessMap.php 1.3 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\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 = [];
  22. /**
  23. * @param array $attributes An array of attributes to pass to the access decision manager (like roles)
  24. * @param string|null $channel The channel to enforce (http, https, or null)
  25. */
  26. public function add(RequestMatcherInterface $requestMatcher, array $attributes = [], string $channel = null)
  27. {
  28. $this->map[] = [$requestMatcher, $attributes, $channel];
  29. }
  30. /**
  31. * {@inheritdoc}
  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 [$elements[1], $elements[2]];
  38. }
  39. }
  40. return [null, null];
  41. }
  42. }