8000 [RFC][HttpFoundation] Introduce RequestMatcher as a namespace by ro0NL · Pull Request #20274 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[RFC][HttpFoundation] Introduce RequestMatcher as a namespace #20274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added standalone expression request matcher
  • Loading branch information
ro0NL committed Oct 22, 2016
commit 0571193079ef5a7a9a6a4d96f7659045ba0f45f4
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpFoundation\RequestMatcher;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

/**
* ExpressionRequestMatcher uses an expression to match a Request.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Roland Franssen <franssen.roland@gmail.com>
*/
class ExpressionRequestMatcher implements RequestMatcherInterface
{
private $language;
private $expression;

public function __construct(ExpressionLanguage $language, $expression)
{
$this->language = $language;
$this->expression = $expression;
}

public function matches(Request $request)
{
return (bool) $this->language->evaluate($this->expression, array(
'request' => $request,
'method' => $request->getMethod(),
'path' => rawurldecode($request->getPathInfo()),
'host' => $request->getHost(),
'ip' => $request->getClientIp(),
'attributes' => $request->attributes->all(),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ public function __construct($path = null, $host = null, array $methods = array()
*/
public function matches(Request $request)
{
if (!parent::matches($request)) {
return false;
}

if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
return false;
}
Expand Down
0