Skip to content

Commit 6c05c17

Browse files
authored
Merge pull request #7646 from kenjis/feat-spark-routes-view-routes
feat: improve View route output
2 parents 54cf146 + 0aa5dbd commit 6c05c17

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

system/Router/DefinedRouteCollector.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function collect(): Generator
5151
if (is_string($handler) || $handler instanceof Closure) {
5252

5353
if ($handler instanceof Closure) {
54-
$handler = '(Closure)';
54+
$view = $this->routeCollection->getRoutesOptions($route, $method)['view'] ?? false;
55+
56+
$handler = $view ? '(View) ' . $view : '(Closure)';
5557
}
5658

5759
$routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route;

system/Router/RouteCollection.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,10 @@ public function view(string $from, string $view, ?array $options = null): RouteC
11011101
->setData(['segments' => $data], 'raw')
11021102
->render($view, $options);
11031103

1104-
$this->create('get', $from, $to, $options);
1104+
$routeOptions = $options ?? [];
1105+
$routeOptions = array_merge($routeOptions, ['view' => $view]);
1106+
1107+
$this->create('get', $from, $to, $routeOptions);
11051108

11061109
return $this;
11071110
}
@@ -1649,7 +1652,7 @@ public function resetRoutes()
16491652
* array{
16501653
* filter?: string|list<string>, namespace?: string, hostname?: string,
16511654
* subdomain?: string, offset?: int, priority?: int, as?: string,
1652-
* redirect?: string
1655+
* redirect?: int
16531656
* }
16541657
* >
16551658
*/

tests/system/Router/DefinedRouteCollectorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testCollect()
8282
'method' => 'get',
8383
'route' => 'about',
8484
'name' => 'about',
85-
'handler' => '(Closure)',
85+
'handler' => '(View) pages/about',
8686
],
8787
];
8888
$this->assertSame($expected, $definedRoutes);

user_guide_src/source/changelogs/v4.4.0.rst

+12-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,17 @@ Enhancements
8383
Commands
8484
========
8585

86-
- Now ``spark routes`` command can specify the host in the request URL.
87-
See :ref:`routing-spark-routes-specify-host`.
86+
- **spark routes:**
87+
- Now you can specify the host in the request URL.
88+
See :ref:`routing-spark-routes-specify-host`.
89+
- It shows view files of :ref:`view-routes` in *Handler* like the following:
90+
91+
+---------+-------------+------+------------------------------+----------------+---------------+
92+
| Method | Route | Name | Handler | Before Filters | After Filters |
93+
+---------+-------------+------+------------------------------+----------------+---------------+
94+
| GET | about | » | (View) pages/about | | toolbar |
95+
+---------+-------------+------+------------------------------+----------------+---------------+
96+
8897

8998
Testing
9099
=======
@@ -151,6 +160,7 @@ Others
151160
- **Error Handling:** Now you can use :ref:`custom-exception-handlers`.
152161
- **RedirectException:** can also take an object that implements ResponseInterface as its first argument.
153162
- **RedirectException:** implements ResponsableInterface.
163+
- **DebugBar:** Now :ref:`view-routes` are displayed in *DEFINED ROUTES* on the *Routes* tab.
154164

155165
Message Changes
156166
***************

0 commit comments

Comments
 (0)