Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpFoundation; Chris@0: Chris@0: use Symfony\Component\ExpressionLanguage\ExpressionLanguage; Chris@0: Chris@0: /** Chris@0: * ExpressionRequestMatcher uses an expression to match a Request. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class ExpressionRequestMatcher extends RequestMatcher Chris@0: { Chris@0: private $language; Chris@0: private $expression; Chris@0: Chris@0: public function setExpression(ExpressionLanguage $language, $expression) Chris@0: { Chris@0: $this->language = $language; Chris@0: $this->expression = $expression; Chris@0: } Chris@0: Chris@0: public function matches(Request $request) Chris@0: { Chris@0: if (!$this->language) { Chris@0: throw new \LogicException('Unable to match the request as the expression language is not available.'); Chris@0: } Chris@0: Chris@17: return $this->language->evaluate($this->expression, [ Chris@0: 'request' => $request, Chris@0: 'method' => $request->getMethod(), Chris@0: 'path' => rawurldecode($request->getPathInfo()), Chris@0: 'host' => $request->getHost(), Chris@0: 'ip' => $request->getClientIp(), Chris@0: 'attributes' => $request->attributes->all(), Chris@17: ]) && parent::matches($request); Chris@0: } Chris@0: }