@@ -53,13 +53,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, UrlMatch
53
53
*/
54
54
public function createRedirectResponse (Request $ request , $ path , $ status = 302 )
55
55
{
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 );
63
57
}
64
58
65
59
/**
@@ -72,14 +66,7 @@ public function createRedirectResponse(Request $request, $path, $status = 302)
72
66
*/
73
67
public function createRequest (Request $ request , $ path )
74
68
{
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 ());
83
70
if ($ session = $ request ->getSession ()) {
84
71
$ newRequest ->setSession ($ session );
85
72
}
@@ -101,7 +88,7 @@ public function createRequest(Request $request, $path)
101
88
* Checks that a given path matches the Request.
102
89
*
103
90
* @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))
105
92
*
106
93
* @return Boolean true if the path is the same as the one from the Request, false otherwise
107
94
*/
@@ -122,6 +109,24 @@ public function checkRequestPath(Request $request, $path)
122
109
return $ path === $ request ->getPathInfo ();
123
110
}
124
111
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
+
125
130
private function generateUrl ($ route , $ absolute = false )
126
131
{
127
132
if (null === $ this ->urlGenerator ) {
0 commit comments