Skip to content

Commit c89c345

Browse files
authored
fix(router): add null checks and fix route parameter handling (#1778)
1 parent bccf92f commit c89c345

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

packages/router/src/RouteBindingInitializer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con
3131
}
3232
}
3333

34+
if ($parameter === null) {
35+
throw new RouteBindingFailed();
36+
}
37+
3438
$object = $class->callStatic('resolve', $matchedRoute->params[$parameter->getName()]);
3539

3640
if ($object === null) {

packages/router/src/Routing/Construction/RoutingTree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private function isOptionalSegment(string $segment): bool
5151

5252
private function stripOptionalMarker(string $segment): string
5353
{
54-
return str_replace('?', '', $segment);
54+
return preg_replace('/^\{\?/', '{', $segment);
5555
}
5656

5757
/** @return array<string, MatchingRegex> */

packages/router/src/UriGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public function isCurrentUri(array|string|MethodReflector $action, mixed ...$par
178178
{
179179
$action = $this->normalizeActionToUri($action);
180180

181+
if (! $this->container->has(MatchedRoute::class)) {
182+
return false;
183+
}
184+
181185
$matchedRoute = $this->container->get(MatchedRoute::class);
182186
$candidateUri = $this->createUri($action, ...[...$matchedRoute->params, ...$params]);
183187
$currentUri = $this->createUri([$matchedRoute->route->handler->getDeclaringClass()->getName(), $matchedRoute->route->handler->getName()]);

0 commit comments

Comments
 (0)