Exception
4 years ago
File
4 years ago
Session
4 years ago
Tests
4 years ago
AcceptHeader.php
4 years ago
AcceptHeaderItem.php
4 years ago
ApacheRequest.php
4 years ago
BinaryFileResponse.php
4 years ago
Cookie.php
4 years ago
ExpressionRequestMatcher.php
4 years ago
FileBag.php
4 years ago
HeaderBag.php
4 years ago
IpUtils.php
4 years ago
JsonResponse.php
4 years ago
LICENSE
4 years ago
ParameterBag.php
4 years ago
RedirectResponse.php
4 years ago
Request.php
4 years ago
RequestMatcher.php
4 years ago
RequestMatcherInterface.php
4 years ago
RequestStack.php
4 years ago
Response.php
4 years ago
ResponseHeaderBag.php
4 years ago
ServerBag.php
4 years ago
StreamedResponse.php
4 years ago
ExpressionRequestMatcher.php
48 lines
| 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\ExpressionLanguage; |
| 15 | |
| 16 | /** |
| 17 | * ExpressionRequestMatcher uses an expression to match a Request. |
| 18 | * |
| 19 | * @author Fabien Potencier <fabien@symfony.com> |
| 20 | */ |
| 21 | class ExpressionRequestMatcher extends RequestMatcher |
| 22 | { |
| 23 | private $language; |
| 24 | private $expression; |
| 25 | |
| 26 | public function setExpression(ExpressionLanguage $language, $expression) |
| 27 | { |
| 28 | $this->language = $language; |
| 29 | $this->expression = $expression; |
| 30 | } |
| 31 | |
| 32 | public function matches(Request $request) |
| 33 | { |
| 34 | if (!$this->language) { |
| 35 | throw new \LogicException('Unable to match the request as the expression language is not available.'); |
| 36 | } |
| 37 | |
| 38 | return $this->language->evaluate($this->expression, [ |
| 39 | 'request' => $request, |
| 40 | 'method' => $request->getMethod(), |
| 41 | 'path' => rawurldecode($request->getPathInfo()), |
| 42 | 'host' => $request->getHost(), |
| 43 | 'ip' => $request->getClientIp(), |
| 44 | 'attributes' => $request->attributes->all(), |
| 45 | ]) && parent::matches($request); |
| 46 | } |
| 47 | } |
| 48 |