File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 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
180180 /**
181181 * Get the path
182182 *
183+ * @param array $replacements
184+ *
183185 * @return string
184186 */
185- public function getPath (): string
187+ public function getPath (array $ replacements = [] ): string
186188 {
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 );
188196 }
189197
190198 /**
Original file line number Diff line number Diff line change @@ -167,4 +167,22 @@ public function process(
167167 $ middleware , $ middleware
168168 ], $ route ->getMiddlewareStack ());
169169 }
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+ }
170188}
You can’t perform that action at this time.
0 commit comments