No Description

ExpressionRequestMatcher.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\HttpFoundation;
  11. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  12. /**
  13. * ExpressionRequestMatcher uses an expression to match a Request.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. class ExpressionRequestMatcher extends RequestMatcher
  18. {
  19. private $language;
  20. private $expression;
  21. public function setExpression(ExpressionLanguage $language, $expression)
  22. {
  23. $this->language = $language;
  24. $this->expression = $expression;
  25. }
  26. public function matches(Request $request)
  27. {
  28. if (!$this->language) {
  29. throw new \LogicException('Unable to match the request as the expression language is not available.');
  30. }
  31. return $this->language->evaluate($this->expression, array(
  32. 'request' => $request,
  33. 'method' => $request->getMethod(),
  34. 'path' => rawurldecode($request->getPathInfo()),
  35. 'host' => $request->getHost(),
  36. 'ip' => $request->getClientIp(),
  37. 'attributes' => $request->attributes->all(),
  38. )) && parent::matches($request);
  39. }
  40. }