File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -180,11 +180,19 @@ public function setParentGroup(RouteGroup $group): self
180
180
/**
181
181
* Get the path
182
182
*
183
+ * @param array $replacements
184
+ *
183
185
* @return string
184
186
*/
185
- public function getPath (): string
187
+ public function getPath (array $ replacements = [] ): string
186
188
{
187
- return $ this ->path ;
189
+ $ toReplace = [];
190
+
191
+ foreach ($ replacements as $ wildcard => $ actual ) {
192
+ $ toReplace ['/{ ' . preg_quote ($ wildcard , '/ ' ) . '(:.*?)?}/ ' ] = $ actual ;
193
+ }
194
+
195
+ return preg_replace (array_keys ($ toReplace ), array_values ($ toReplace ), $ this ->path );
188
196
}
189
197
190
198
/**
Original file line number Diff line number Diff line change @@ -167,4 +167,22 @@ public function process(
167
167
$ middleware , $ middleware
168
168
], $ route ->getMiddlewareStack ());
169
169
}
170
+
171
+ /**
172
+ * Asserts that passing actual values to getPath replaces the wildcards.
173
+ *
174
+ * @return void
175
+ */
176
+ public function testGetPathReplacesWildcards ()
177
+ {
178
+ $ route = new Route ('GET ' , '/a/{wildcard}/and/{wildcardWithMatcher:uuid} ' , function () {
179
+ });
180
+
181
+ $ path = $ route ->getPath ([
182
+ 'wildcard ' => 'replaced-wildcard ' ,
183
+ 'wildcardWithMatcher ' => 'replaced-wildcard-with-matcher ' ,
184
+ ]);
185
+
186
+ $ this ->assertSame ('/a/replaced-wildcard/and/replaced-wildcard-with-matcher ' , $ path );
187
+ }
170
188
}
You can’t perform that action at this time.
0 commit comments