Skip to content

Commit 6d2cefc

Browse files
committed
fix: $cliRoutes contains only CLI routes, not '*' routes
1 parent f96e132 commit 6d2cefc

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

system/Router/AutoRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
final class AutoRouter implements AutoRouterInterface
2121
{
2222
/**
23-
* List of CLI routes.
23+
* List of CLI routes that do not contain '*' routes.
2424
*
2525
* @var array<string, Closure|string> [routeKey => handler]
2626
*/

system/Router/RouteCollection.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,10 @@ public function shouldAutoRoute(): bool
484484

485485
/**
486486
* Returns the raw array of available routes.
487+
*
488+
* @param bool $only Whether to return without '*' routes.
487489
*/
488-
public function getRoutes(?string $verb = null): array
490+
public function getRoutes(?string $verb = null, bool $only = false): array
489491
{
490492
if (empty($verb)) {
491493
$verb = $this->getHTTPVerb();
@@ -501,7 +503,11 @@ public function getRoutes(?string $verb = null): array
501503
if (isset($this->routes[$verb])) {
502504
// Keep current verb's routes at the beginning, so they're matched
503505
// before any of the generic, "add" routes.
504-
$collection = $this->routes[$verb] + ($this->routes['*'] ?? []);
506+
if (! $only) {
507+
$collection = $this->routes[$verb] + ($this->routes['*'] ?? []);
508+
} else {
509+
$collection = $this->routes[$verb];
510+
}
505511

506512
foreach ($collection as $r) {
507513
$key = key($r['route']);

system/Router/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request
145145
);
146146
} else {
147147
$this->autoRouter = new AutoRouter(
148-
$this->collection->getRoutes('cli'), // @phpstan-ignore-line
148+
$this->collection->getRoutes('cli', true), // @phpstan-ignore-line
149149
$this->collection->getDefaultNamespace(),
150150
$this->collection->getDefaultController(),
151151
$this->collection->getDefaultMethod(),

0 commit comments

Comments
 (0)