| 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\RequestMatcher;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\ExpressionLanguage\Expression;
|
|
|
15 |
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
|
|
16 |
use Symfony\Component\HttpFoundation\Request;
|
|
|
17 |
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* ExpressionRequestMatcher uses an expression to match a Request.
|
|
|
21 |
*
|
|
|
22 |
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
23 |
*/
|
|
|
24 |
class ExpressionRequestMatcher implements RequestMatcherInterface
|
|
|
25 |
{
|
|
|
26 |
public function __construct(
|
|
|
27 |
private ExpressionLanguage $language,
|
|
|
28 |
private Expression|string $expression,
|
|
|
29 |
) {
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public function matches(Request $request): bool
|
|
|
33 |
{
|
|
|
34 |
return $this->language->evaluate($this->expression, [
|
|
|
35 |
'request' => $request,
|
|
|
36 |
'method' => $request->getMethod(),
|
|
|
37 |
'path' => rawurldecode($request->getPathInfo()),
|
|
|
38 |
'host' => $request->getHost(),
|
|
|
39 |
'ip' => $request->getClientIp(),
|
|
|
40 |
'attributes' => $request->attributes->all(),
|
|
|
41 |
]);
|
|
|
42 |
}
|
|
|
43 |
}
|