Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, [
  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. }