1
1
// This file was generated from php-templates/routes.php, do not edit directly
2
2
export default `
3
- function vsCodeGetRouterReflection(\\Illuminate\\Routing\\Route $route)
4
- {
5
- if ($route->getActionName() === 'Closure') {
6
- return new \\ReflectionFunction($route->getAction()['uses']);
3
+ $routes = new class {
4
+ public function all()
5
+ {
6
+ return collect(app('router')->getRoutes()->getRoutes())
7
+ ->map(fn(\\Illuminate\\Routing\\Route $route) => $this->getRoute($route))
8
+ ->merge($this->getFolioRoutes());
7
9
}
8
10
9
- if (!str_contains($route->getActionName(), '@')) {
10
- return new \\ReflectionClass($route->getActionName());
11
+ protected function getFolioRoutes()
12
+ {
13
+ try {
14
+ $output = new \\Symfony\\Component\\Console\\Output\\BufferedOutput();
15
+
16
+ \\Illuminate\\Support\\Facades\\Artisan::call("folio:list", ["--json" => true], $output);
17
+
18
+ $mountPaths = collect(app(\\Laravel\\Folio\\FolioManager::class)->mountPaths());
19
+
20
+ return collect(json_decode($output->fetch(), true))->map(fn($route) => $this->getFolioRoute($route, $mountPaths));
21
+ } catch (\\Exception | \\Throwable $e) {
22
+ return [];
23
+ }
11
24
}
12
25
13
- try {
14
- return new \\ReflectionMethod($route->getControllerClass(), $route->getActionMethod());
15
- } catch (\\Throwable $e) {
16
- $namespace = app(\\Illuminate\\Routing\\UrlGenerator::class)->getRootControllerNamespace()
17
- ?? (app()->getNamespace() . 'Http\\Controllers');
26
+ protected function getFolioRoute($route, $mountPaths)
27
+ {
28
+ if ($mountPaths->count() === 1) {
29
+ $mountPath = $mountPaths[0];
30
+ } else {
31
+ $mountPath = $mountPaths->first(fn($mp) => file_exists($mp->path . DIRECTORY_SEPARATOR . $route['view']));
32
+ }
33
+
34
+ $path = $route['view'];
35
+
36
+ if ($mountPath) {
37
+ $path = $mountPath->path . DIRECTORY_SEPARATOR . $path;
38
+ }
18
39
19
- return new \\ReflectionMethod(
20
- $namespace . '\\\\' . ltrim($route->getControllerClass(), '\\\\'),
21
- $route->getActionMethod(),
22
- );
40
+ return [
41
+ 'method' => $route['method'],
42
+ 'uri' => $route['uri'],
43
+ 'name' => $route['name'],
44
+ 'action' => null,
45
+ 'parameters' => [],
46
+ 'filename' => $path,
47
+ 'line' => 0,
48
+ ];
23
49
}
24
- }
25
50
26
- echo collect(app('router')->getRoutes()->getRoutes() )
27
- ->map(function (\\Illuminate\\Routing\\Route $route) {
51
+ protected function getRoute(\\Illuminate\\Routing\\Route $route )
52
+ {
28
53
try {
29
- $reflection = vsCodeGetRouterReflection ($route);
54
+ $reflection = $this->getRouteReflection ($route);
30
55
} catch (\\Throwable $e) {
31
56
$reflection = null;
32
57
}
33
58
34
59
return [
35
- 'method' => collect($route->methods())->filter(function ($method) {
36
- return $method !== 'HEAD';
37
- }) ->implode('|'),
60
+ 'method' => collect($route->methods())
61
+ ->filter(fn($method) => $method !== 'HEAD')
62
+ ->implode('|'),
38
63
'uri' => $route->uri(),
39
64
'name' => $route->getName(),
40
65
'action' => $route->getActionName(),
41
66
'parameters' => $route->parameterNames(),
42
67
'filename' => $reflection ? $reflection->getFileName() : null,
43
68
'line' => $reflection ? $reflection->getStartLine() : null,
44
69
];
45
- })
46
- ->toJson();
70
+ }
71
+
72
+ protected function getRouteReflection(\\Illuminate\\Routing\\Route $route)
73
+ {
74
+ if ($route->getActionName() === 'Closure') {
75
+ return new \\ReflectionFunction($route->getAction()['uses']);
76
+ }
77
+
78
+ if (!str_contains($route->getActionName(), '@')) {
79
+ return new \\ReflectionClass($route->getActionName());
80
+ }
81
+
82
+ try {
83
+ return new \\ReflectionMethod($route->getControllerClass(), $route->getActionMethod());
84
+ } catch (\\Throwable $e) {
85
+ $namespace = app(\\Illuminate\\Routing\\UrlGenerator::class)->getRootControllerNamespace()
86
+ ?? (app()->getNamespace() . 'Http\\Controllers');
87
+
88
+ return new \\ReflectionMethod(
89
+ $namespace . '\\\\' . ltrim($route->getControllerClass(), '\\\\'),
90
+ $route->getActionMethod(),
91
+ );
92
+ }
93
+ }
94
+ };
95
+
96
+
97
+ echo $routes->all()->toJson();
47
98
` ;
0 commit comments