Skip to content

Commit c924479

Browse files
committed
gracefully continue
1 parent 6bbc89c commit c924479

File tree

1 file changed

+57
-52
lines changed

1 file changed

+57
-52
lines changed

src/Processors/RouteProcessor.php

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Routing\Route;
1010
use Illuminate\Routing\Router;
1111
use Illuminate\Support\Collection;
12+
use Illuminate\Support\Facades\Log;
1213
use Illuminate\Support\Facades\Validator;
1314
use Illuminate\Support\Str;
1415
use Illuminate\Support\Stringable;
@@ -54,80 +55,84 @@ public function process(array $output): array
5455
*/
5556
protected function processRoute(Route $route)
5657
{
57-
$methods = array_filter($route->methods(), fn ($value) => $value !== 'HEAD');
58-
$middlewares = $route->gatherMiddleware();
58+
try {
59+
$methods = array_filter($route->methods(), fn ($value) => $value !== 'HEAD');
60+
$middlewares = $route->gatherMiddleware();
5961

60-
foreach ($methods as $method) {
61-
$includedMiddleware = false;
62+
foreach ($methods as $method) {
63+
$includedMiddleware = false;
6264

63-
foreach ($middlewares as $middleware) {
64-
if (in_array($middleware, $this->config['include_middleware'])) {
65-
$includedMiddleware = true;
65+
foreach ($middlewares as $middleware) {
66+
if (in_array($middleware, $this->config['include_middleware'])) {
67+
$includedMiddleware = true;
68+
}
6669
}
67-
}
6870

69-
if (empty($middlewares) || ! $includedMiddleware) {
70-
continue;
71-
}
71+
if (empty($middlewares) || ! $includedMiddleware) {
72+
continue;
73+
}
7274

73-
$reflectionMethod = $this->getReflectionMethod($route->getAction());
75+
$reflectionMethod = $this->getReflectionMethod($route->getAction());
7476

75-
if (! $reflectionMethod) {
76-
continue;
77-
}
77+
if (! $reflectionMethod) {
78+
continue;
79+
}
7880

79-
$routeHeaders = $this->config['headers'];
81+
$routeHeaders = $this->config['headers'];
8082

81-
if ($this->authentication && in_array($this->config['auth_middleware'], $middlewares)) {
82-
$routeHeaders[] = $this->authentication->toArray();
83-
}
83+
if ($this->authentication && in_array($this->config['auth_middleware'], $middlewares)) {
84+
$routeHeaders[] = $this->authentication->toArray();
85+
}
8486

85-
$uri = Str::of($route->uri())
86-
->after('/')
87-
->replaceMatches('/{([[:alnum:]]+)}/', ':$1');
87+
$uri = Str::of($route->uri())
88+
->after('/')
89+
->replaceMatches('/{([[:alnum:]]+)}/', ':$1');
8890

89-
// if (!$uri->toString()) {
90-
// return [];
91-
// }
91+
// if (!$uri->toString()) {
92+
// return [];
93+
// }
9294

93-
if ($this->config['include_doc_comments']) {
94-
$description = (new DocBlockProcessor)($reflectionMethod);
95-
}
95+
if ($this->config['include_doc_comments']) {
96+
$description = (new DocBlockProcessor)($reflectionMethod);
97+
}
9698

97-
$data = [
98-
'name' => $route->uri(),
99-
'request' => array_merge(
100-
$this->processRequest(
101-
$method,
102-
$uri,
103-
$this->config['enable_formdata'] ? (new FormDataProcessor)->process($reflectionMethod) : collect()
99+
$data = [
100+
'name' => $route->uri(),
101+
'request' => array_merge(
102+
$this->processRequest(
103+
$method,
104+
$uri,
105+
$this->config['enable_formdata'] ? (new FormDataProcessor)->process($reflectionMethod) : collect()
106+
),
107+
['description' => $description ?? '']
104108
),
105-
['description' => $description ?? '']
106-
),
107-
'response' => [],
109+
'response' => [],
108110

109-
'protocolProfileBehavior' => [
110-
'disableBodyPruning' => $this->config['protocol_profile_behavior']['disable_body_pruning'] ?? false,
111-
],
112-
];
111+
'protocolProfileBehavior' => [
112+
'disableBodyPruning' => $this->config['protocol_profile_behavior']['disable_body_pruning'] ?? false,
113+
],
114+
];
113115

114-
if ($this->config['structured']) {
115-
$routeNameSegments = (
116+
if ($this->config['structured']) {
117+
$routeNameSegments = (
116118
$route->getName()
117119
? Str::of($route->getName())->explode('.')
118120
: Str::of($route->uri())->after('api/')->explode('/')
119-
)->filter(fn ($value) => ! is_null($value) && $value !== '');
121+
)->filter(fn ($value) => ! is_null($value) && $value !== '');
120122

121-
if (! $this->config['crud_folders']) {
122-
if (in_array($routeNameSegments->last(), ['index', 'store', 'show', 'update', 'destroy'])) {
123-
$routeNameSegments->forget($routeNameSegments->count() - 1);
123+
if (! $this->config['crud_folders']) {
124+
if (in_array($routeNameSegments->last(), ['index', 'store', 'show', 'update', 'destroy'])) {
125+
$routeNameSegments->forget($routeNameSegments->count() - 1);
126+
}
124127
}
125-
}
126128

127-
$this->buildTree($this->output, $routeNameSegments->all(), $data);
128-
} else {
129-
$this->output['item'][] = $data;
129+
$this->buildTree($this->output, $routeNameSegments->all(), $data);
130+
} else {
131+
$this->output['item'][] = $data;
132+
}
130133
}
134+
} catch (\Exception $e) {
135+
Log::warning('Failed to process route: '.$route->uri());
131136
}
132137
}
133138

0 commit comments

Comments
 (0)