diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2012-06-26 11:30:41 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2012-06-26 11:30:41 +0200 |
commit | 2af0fd6cc0369ae740a1be321cce46e87e9eb519 (patch) | |
tree | 1f0125f1ef4e6f2c963c4e17a7a1870ecad1cf49 /Http/HttpUtils.php | |
parent | a86fab245763a1bb7e81a55d5acb621cf3f31345 (diff) | |
download | symfony-security-2af0fd6cc0369ae740a1be321cce46e87e9eb519.zip symfony-security-2af0fd6cc0369ae740a1be321cce46e87e9eb519.tar.gz symfony-security-2af0fd6cc0369ae740a1be321cce46e87e9eb519.tar.bz2 |
[Security] simplified some code
Diffstat (limited to 'Http/HttpUtils.php')
-rw-r--r-- | Http/HttpUtils.php | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/Http/HttpUtils.php b/Http/HttpUtils.php index de40e1e..aeafde6 100644 --- a/Http/HttpUtils.php +++ b/Http/HttpUtils.php @@ -53,13 +53,7 @@ class HttpUtils */ public function createRedirectResponse(Request $request, $path, $status = 302) { - if ('/' === $path[0]) { - $path = $request->getUriForPath($path); - } elseif (0 !== strpos($path, 'http')) { - $path = $this->generateUrl($path, true); - } - - return new RedirectResponse($path, $status); + return new RedirectResponse($this->generateUri($request, $path), $status); } /** @@ -72,14 +66,7 @@ class HttpUtils */ public function createRequest(Request $request, $path) { - if ($path && '/' !== $path[0] && 0 !== strpos($path, 'http')) { - $path = $this->generateUrl($path, true); - } - if (0 !== strpos($path, 'http')) { - $path = $request->getUriForPath($path); - } - - $newRequest = Request::create($path, 'get', array(), $request->cookies->all(), array(), $request->server->all()); + $newRequest = Request::create($this->generateUri($request, $path), 'get', array(), $request->cookies->all(), array(), $request->server->all()); if ($session = $request->getSession()) { $newRequest->setSession($session); } @@ -101,7 +88,7 @@ class HttpUtils * Checks that a given path matches the Request. * * @param Request $request A Request instance - * @param string $path A path (an absolute path (/foo) or a route name (foo)) + * @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo)) * * @return Boolean true if the path is the same as the one from the Request, false otherwise */ @@ -122,6 +109,24 @@ class HttpUtils return $path === $request->getPathInfo(); } + /** + * Generates a URI, based on the given path or absolute URL. + * + * @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo)) + */ + public function generateUri($request, $path) + { + if (0 === strpos($path, 'http') || !$path) { + return $path; + } + + if ($path && '/' === $path[0]) { + return $request->getUriForPath($path); + } + + return $this->generateUrl($path, true); + } + private function generateUrl($route, $absolute = false) { if (null === $this->urlGenerator) { |