|
9 | 9 | use Illuminate\Routing\Route;
|
10 | 10 | use Illuminate\Routing\Router;
|
11 | 11 | use Illuminate\Support\Collection;
|
| 12 | +use Illuminate\Support\Facades\Log; |
12 | 13 | use Illuminate\Support\Facades\Validator;
|
13 | 14 | use Illuminate\Support\Str;
|
14 | 15 | use Illuminate\Support\Stringable;
|
@@ -54,80 +55,84 @@ public function process(array $output): array
|
54 | 55 | */
|
55 | 56 | protected function processRoute(Route $route)
|
56 | 57 | {
|
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(); |
59 | 61 |
|
60 |
| - foreach ($methods as $method) { |
61 |
| - $includedMiddleware = false; |
| 62 | + foreach ($methods as $method) { |
| 63 | + $includedMiddleware = false; |
62 | 64 |
|
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 | + } |
66 | 69 | }
|
67 |
| - } |
68 | 70 |
|
69 |
| - if (empty($middlewares) || ! $includedMiddleware) { |
70 |
| - continue; |
71 |
| - } |
| 71 | + if (empty($middlewares) || ! $includedMiddleware) { |
| 72 | + continue; |
| 73 | + } |
72 | 74 |
|
73 |
| - $reflectionMethod = $this->getReflectionMethod($route->getAction()); |
| 75 | + $reflectionMethod = $this->getReflectionMethod($route->getAction()); |
74 | 76 |
|
75 |
| - if (! $reflectionMethod) { |
76 |
| - continue; |
77 |
| - } |
| 77 | + if (! $reflectionMethod) { |
| 78 | + continue; |
| 79 | + } |
78 | 80 |
|
79 |
| - $routeHeaders = $this->config['headers']; |
| 81 | + $routeHeaders = $this->config['headers']; |
80 | 82 |
|
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 | + } |
84 | 86 |
|
85 |
| - $uri = Str::of($route->uri()) |
86 |
| - ->after('/') |
87 |
| - ->replaceMatches('/{([[:alnum:]]+)}/', ':$1'); |
| 87 | + $uri = Str::of($route->uri()) |
| 88 | + ->after('/') |
| 89 | + ->replaceMatches('/{([[:alnum:]]+)}/', ':$1'); |
88 | 90 |
|
89 |
| - // if (!$uri->toString()) { |
90 |
| - // return []; |
91 |
| - // } |
| 91 | + // if (!$uri->toString()) { |
| 92 | + // return []; |
| 93 | + // } |
92 | 94 |
|
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 | + } |
96 | 98 |
|
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 ?? ''] |
104 | 108 | ),
|
105 |
| - ['description' => $description ?? ''] |
106 |
| - ), |
107 |
| - 'response' => [], |
| 109 | + 'response' => [], |
108 | 110 |
|
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 | + ]; |
113 | 115 |
|
114 |
| - if ($this->config['structured']) { |
115 |
| - $routeNameSegments = ( |
| 116 | + if ($this->config['structured']) { |
| 117 | + $routeNameSegments = ( |
116 | 118 | $route->getName()
|
117 | 119 | ? Str::of($route->getName())->explode('.')
|
118 | 120 | : Str::of($route->uri())->after('api/')->explode('/')
|
119 |
| - )->filter(fn ($value) => ! is_null($value) && $value !== ''); |
| 121 | + )->filter(fn ($value) => ! is_null($value) && $value !== ''); |
120 | 122 |
|
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 | + } |
124 | 127 | }
|
125 |
| - } |
126 | 128 |
|
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 | + } |
130 | 133 | }
|
| 134 | + } catch (\Exception $e) { |
| 135 | + Log::warning('Failed to process route: '.$route->uri()); |
131 | 136 | }
|
132 | 137 | }
|
133 | 138 |
|
|
0 commit comments