From d2af631c049339dac33f1d15d7e336653b4a447c Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 4 Jul 2023 13:12:54 +0900 Subject: [PATCH] feat: improve `spark routes` output for View routes --- system/Router/DefinedRouteCollector.php | 4 +++- system/Router/RouteCollection.php | 5 ++++- tests/system/Router/DefinedRouteCollectorTest.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/system/Router/DefinedRouteCollector.php b/system/Router/DefinedRouteCollector.php index c1d98a5ea95b..dd7403575ba9 100644 --- a/system/Router/DefinedRouteCollector.php +++ b/system/Router/DefinedRouteCollector.php @@ -48,7 +48,9 @@ public function collect(): Generator if (is_string($handler) || $handler instanceof Closure) { if ($handler instanceof Closure) { - $handler = '(Closure)'; + $view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false; + + $handler = $view ? '(View) ' . $view : '(Closure)'; } $routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route; diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 777681144dc3..ac0903a3ea8f 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1101,7 +1101,10 @@ public function view(string $from, string $view, ?array $options = null): RouteC ->setData(['segments' => $data], 'raw') ->render($view, $options); - $this->create('get', $from, $to, $options); + $routeOptions = $options ?? []; + $routeOptions = array_merge($routeOptions, ['view' => $view]); + + $this->create('get', $from, $to, $routeOptions); return $this; } diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php index 61647967766c..84d8f800f04e 100644 --- a/tests/system/Router/DefinedRouteCollectorTest.php +++ b/tests/system/Router/DefinedRouteCollectorTest.php @@ -82,7 +82,7 @@ public function test() 'method' => 'get', 'route' => 'about', 'name' => 'about', - 'handler' => '(Closure)', + 'handler' => '(View) pages/about', ], ]; $this->assertSame($expected, $definedRoutes);