Skip to content

Commit 64c7b7b

Browse files
authored
Merge pull request #167 from utopia-php/fix-breaking-change
Fix: Breaking changes
2 parents 71d7e75 + 916424c commit 64c7b7b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Route.php

Lines changed: 9 additions & 3 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 $path, string $key, int $index): void
157+
public function setPathParam(string $key, int $index, string $path = ''): void
158158
{
159159
$this->pathParams[$path][$key] = $index;
160160
}
@@ -165,12 +165,18 @@ public function setPathParam(string $path, string $key, int $index): 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-
foreach (($this->pathParams[$path] ?? []) as $key => $index) {
173+
if (empty($path)) {
174+
$pathParams = $this->pathParams[$path] ?? \array_values($this->pathParams)[0] ?? [];
175+
} else {
176+
$pathParams = $this->pathParams[$path] ?? [];
177+
}
178+
179+
foreach ($pathParams as $key => $index) {
174180
if (array_key_exists($index, $parts)) {
175181
$pathValues[$key] = $parts[$index];
176182
}

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($path, $key, $index);
89+
$route->setPathParam($key, $index, $path);
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($alias, $key, $index);
111+
$route->setPathParam($key, $index, $alias);
112112
}
113113

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

0 commit comments

Comments
 (0)