Skip to content

Commit

Permalink
feat: improve spark routes output for View routes
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 4, 2023
1 parent c1b8f4d commit d2af631
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion system/Router/DefinedRouteCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Router/DefinedRouteCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function test()
'method' => 'get',
'route' => 'about',
'name' => 'about',
'handler' => '(Closure)',
'handler' => '(View) pages/about',
],
];
$this->assertSame($expected, $definedRoutes);
Expand Down

0 comments on commit d2af631

Please sign in to comment.