diff options
author | David Buchmann <david.buchmann@liip.ch> | 2012-12-22 11:07:13 +0100 |
---|---|---|
committer | David Buchmann <david.buchmann@liip.ch> | 2012-12-23 11:45:18 +0100 |
commit | 8345449ea897dd8b3e5dd0bc62705722cc1c0827 (patch) | |
tree | 53e50e3cff8a36b676a6176ded158deda1c0076d /Http/HttpUtils.php | |
parent | 78e25f39b81ccadc5ead77f2c1e1099492875a9c (diff) | |
download | symfony-security-8345449ea897dd8b3e5dd0bc62705722cc1c0827.zip symfony-security-8345449ea897dd8b3e5dd0bc62705722cc1c0827.tar.gz symfony-security-8345449ea897dd8b3e5dd0bc62705722cc1c0827.tar.bz2 |
HttpUtils must handle RequestMatcher too
Diffstat (limited to 'Http/HttpUtils.php')
-rw-r--r-- | Http/HttpUtils.php | 17 |
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) { |