Skip to content

Commit 71d7e75

Browse files
committed
Revert "Avoid breaking change"
This reverts commit f1f293c.
1 parent 3ee429f commit 71d7e75

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/Route.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function getHook(): bool
154154
* @param int $index
155155
* @return void
156156
*/
157-
public function setPathParam(string $key, int $index, string $path = ''): void
157+
public function setPathParam(string $path, string $key, int $index): void
158158
{
159159
$this->pathParams[$path][$key] = $index;
160160
}
@@ -165,18 +165,12 @@ public function setPathParam(string $key, int $index, string $path = ''): void
165165
* @param \Utopia\Request $request
166166
* @return array
167167
*/
168-
public function getPathValues(Request $request, string $path = ''): array
168+
public function getPathValues(Request $request, string $path): array
169169
{
170170
$pathValues = [];
171171
$parts = explode('/', ltrim($request->getURI(), '/'));
172172

173-
if(empty($path)) {
174-
$pathParams = $this->pathParams[$path] ?? $this->pathParams[0] ?? [];
175-
} else {
176-
$pathParams = $this->pathParams[$path] ?? [];
177-
}
178-
179-
foreach ($pathParams as $key => $index) {
173+
foreach (($this->pathParams[$path] ?? []) as $key => $index) {
180174
if (array_key_exists($index, $parts)) {
181175
$pathValues[$key] = $parts[$index];
182176
}

src/Router.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function addRoute(Route $route): void
8686
}
8787

8888
foreach ($params as $key => $index) {
89-
$route->setPathParam($key, $index, $path);
89+
$route->setPathParam($path, $key, $index);
9090
}
9191

9292
self::$routes[$route->getMethod()][$path] = $route;
@@ -108,7 +108,7 @@ public static function addRouteAlias(string $path, Route $route): void
108108
}
109109

110110
foreach ($params as $key => $index) {
111-
$route->setPathParam($key, $index, $alias);
111+
$route->setPathParam($alias, $key, $index);
112112
}
113113

114114
self::$routes[$route->getMethod()][$alias] = $route;

0 commit comments

Comments
 (0)