summaryrefslogtreecommitdiffstats
path: root/Http
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2013-01-02 10:30:52 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2013-01-02 10:30:52 +0100
commit4166041efbbd1f8411c5e6697572ec0945f1d606 (patch)
tree9f66089c5161b4732b96e848cbfce99942c01256 /Http
parent52e8d757711320d5a9fa1ec20bf74048411d1d2d (diff)
parent8345449ea897dd8b3e5dd0bc62705722cc1c0827 (diff)
downloadsymfony-security-4166041efbbd1f8411c5e6697572ec0945f1d606.zip
symfony-security-4166041efbbd1f8411c5e6697572ec0945f1d606.tar.gz
symfony-security-4166041efbbd1f8411c5e6697572ec0945f1d606.tar.bz2
merged branch dbu/2.1-requestmatcher-httputils (PR #6470)
This PR was merged into the 2.1 branch. Commits ------- bfccd28 HttpUtils must handle RequestMatcher too Discussion ---------- HttpUtils must handle RequestMatcher too 2.1 introduced the RequestMatcher as alternative to UrlMatcher. but HttpUtils was not adjusted. --------------------------------------------------------------------------- by lsmith77 at 2013-01-01T18:15:13Z @fabpot could you have a look at this PR? would like to know if this will be addressed in core or if we need to find another solution inside the CMF routing.
Diffstat (limited to 'Http')
-rw-r--r--Http/HttpUtils.php17
1 files changed, 13 insertions, 4 deletions
diff --git a/Http/HttpUtils.php b/Http/HttpUtils.php
index 76cfc6a..746b217 100644
--- a/Http/HttpUtils.php
+++ b/Http/HttpUtils.php
@@ -16,6 +16,7 @@ use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
+use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@@ -33,12 +34,15 @@ class HttpUtils
/**
* Constructor.
*
- * @param UrlGeneratorInterface $urlGenerator A UrlGeneratorInterface instance
- * @param UrlMatcherInterface $urlMatcher A UrlMatcherInterface instance
+ * @param UrlGeneratorInterface $urlGenerator A UrlGeneratorInterface instance
+ * @param UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
*/
- public function __construct(UrlGeneratorInterface $urlGenerator = null, UrlMatcherInterface $urlMatcher = null)
+ public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatcher = null)
{
$this->urlGenerator = $urlGenerator;
+ if ($urlMatcher !== null && !$urlMatcher instanceof UrlMatcherInterface && !$urlMatcher instanceof RequestMatcherInterface) {
+ throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
+ }
$this->urlMatcher = $urlMatcher;
}
@@ -96,7 +100,12 @@ class HttpUtils
{
if ('/' !== $path[0]) {
try {
- $parameters = $this->urlMatcher->match($request->getPathInfo());
+ // matching a request is more powerful than matching a URL path + context, so try that first
+ if ($this->urlMatcher instanceof RequestMatcherInterface) {
+ $parameters = $this->urlMatcher->matchRequest($request);
+ } else {
+ $parameters = $this->urlMatcher->match($request->getPathInfo());
+ }
return $path === $parameters['_route'];
} catch (MethodNotAllowedException $e) {