| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\HttpFoundation;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\ExpressionLanguage\Expression;
|
|
|
15 |
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|
|
16 |
use Symfony\Component\HttpFoundation\RequestMatcher\ExpressionRequestMatcher as NewExpressionRequestMatcher;
|
|
|
17 |
|
|
|
18 |
trigger_deprecation('symfony/http-foundation', '6.2', 'The "%s" class is deprecated, use "%s" instead.', ExpressionRequestMatcher::class, NewExpressionRequestMatcher::class);
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* ExpressionRequestMatcher uses an expression to match a Request.
|
|
|
22 |
*
|
|
|
23 |
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
24 |
*
|
|
|
25 |
* @deprecated since Symfony 6.2, use "Symfony\Component\HttpFoundation\RequestMatcher\ExpressionRequestMatcher" instead
|
|
|
26 |
*/
|
|
|
27 |
class ExpressionRequestMatcher extends RequestMatcher
|
|
|
28 |
{
|
|
|
29 |
private ExpressionLanguage $language;
|
|
|
30 |
private Expression|string $expression;
|
|
|
31 |
|
|
|
32 |
public function setExpression(ExpressionLanguage $language, Expression|string $expression)
|
|
|
33 |
{
|
|
|
34 |
$this->language = $language;
|
|
|
35 |
$this->expression = $expression;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public function matches(Request $request): bool
|
|
|
39 |
{
|
|
|
40 |
if (!isset($this->language)) {
|
|
|
41 |
throw new \LogicException('Unable to match the request as the expression language is not available.');
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
return $this->language->evaluate($this->expression, [
|
|
|
45 |
'request' => $request,
|
|
|
46 |
'method' => $request->getMethod(),
|
|
|
47 |
'path' => rawurldecode($request->getPathInfo()),
|
|
|
48 |
'host' => $request->getHost(),
|
|
|
49 |
'ip' => $request->getClientIp(),
|
|
|
50 |
'attributes' => $request->attributes->all(),
|
|
|
51 |
]) && parent::matches($request);
|
|
|
52 |
}
|
|
|
53 |
}
|