8000 [Security] simplified some code · Rodsevich/symfony@21e2f29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21e2f29

Browse files
committed
[Security] simplified some code
1 parent 16a0af1 commit 21e2f29

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/Symfony/Component/Security/Http/HttpUtils.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, UrlMatch
5353
*/
5454
public function createRedirectResponse(Request $request, $path, $status = 302)
5555
{
56-
if ('/' === $path[0]) {
57-
$path = $request->getUriForPath($path);
58-
} elseif (0 !== strpos($path, 'http')) {
59-
$path = $this->generateUrl($path, true);
60-
}
61-
62-
return new RedirectResponse($path, $status);
56+
return new RedirectResponse($this->generateUri($request, $path), $status);
6357
}
6458

6559
/**
@@ -72,14 +66,7 @@ public function createRedirectResponse(Request $request, $path, $status = 302)
7266
*/
7367
public function createRequest(Request $request, $path)
7468
{
75-
if ($path && '/' !== $path[0] && 0 !== strpos($path, 'http')) {
76-
$path = $this->generateUrl($path, true);
77-
}
78-
if (0 !== strpos($path, 'http')) {
79-
$path = $request->getUriForPath($path);
80-
}
81-
82-
$newRequest = Request::create($path, 'get', array(), $request->cookies->all(), array(), $request->server->all());
69+
$newRequest = Request::create($this->generateUri($request, $path), 'get', array(), $request->cookies->all(), array(), $request->server->all());
8370
if ($session = $request->getSession()) {
8471
$newRequest->setSession($session);
8572
}
@@ -101,7 +88,7 @@ public function createRequest(Request $request, $path)
10188
* Checks that a given path matches the Request.
10289
*
10390
* @param Request $request A Request instance
104-
* @param string $path A path (an absolute path (/foo) or a route name (foo))
91+
* @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
10592
*
10693
* @return Boolean true if the path is the same as the one from the Request, false otherwise
10794
*/
@@ -122,6 +109,24 @@ public function checkRequestPath(Request $request, $path)
122109
return $path === $request->getPathInfo();
123110
}
124111

112+
/**
113+
* Generates a URI, based on the given path or absolute URL.
114+
*
115+
* @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
116+
*/
117+
public function generateUri($request, $path)
118+
{
119+
if (0 === strpos($path, 'http') || !$path) {
120+
return $path;
121+
}
122+
123+
if ($path && '/' === $path[0]) {
124+
return $request->getUriForPath($path);
125+
}
126+
127+
return $this->generateUrl($path, true);
128+
}
129+
125130
private function generateUrl($route, $absolute = false)
126131
{
127132
if (null === $this->urlGenerator) {

0 commit comments

Comments
 (0)
0