1 | <?php |
||
14 | class GenerateDocumentation extends Command |
||
15 | { |
||
16 | /** |
||
17 | * The name and signature of the console command. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $signature = 'api:generate |
||
22 | {--output=public/docs : The output path for the generated documentation} |
||
23 | {--routePrefix= : The route prefix to use for generation} |
||
24 | {--routes=* : The route names to use for generation} |
||
25 | {--noResponseCalls : Disable API response calls} |
||
26 | {--noPostmanCollection : Disable Postman collection creation} |
||
27 | {--actAsUserId= : The user ID to use for API response calls} |
||
28 | {--router=laravel : The router to be used (Laravel or Dingo)} |
||
29 | {--bindings= : Route Model Bindings} |
||
30 | '; |
||
31 | |||
32 | /** |
||
33 | * The console command description. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $description = 'Generate your API documentation from existing Laravel routes.'; |
||
38 | |||
39 | /** |
||
40 | * Create a new command instance. |
||
41 | * |
||
42 | * @return void |
||
|
|||
43 | */ |
||
44 | public function __construct() |
||
48 | |||
49 | /** |
||
50 | * Execute the console command. |
||
51 | * |
||
52 | * @return false|null |
||
53 | */ |
||
54 | public function handle() |
||
82 | |||
83 | /** |
||
84 | * @param Collection $parsedRoutes |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | private function writeMarkdown($parsedRoutes) |
||
120 | |||
121 | /** |
||
122 | * @return array |
||
123 | */ |
||
124 | private function getBindings() |
||
139 | |||
140 | /** |
||
141 | * @param $actAs |
||
142 | */ |
||
143 | private function setUserToBeImpersonated($actAs) |
||
157 | |||
158 | /** |
||
159 | * @return mixed |
||
160 | */ |
||
161 | private function getRoutes() |
||
169 | |||
170 | /** |
||
171 | * @param AbstractGenerator $generator |
||
172 | * @param $allowedRoutes |
||
173 | * @param $routePrefix |
||
174 | * |
||
175 | * @return array |
||
176 | */ |
||
177 | private function processLaravelRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) |
||
196 | |||
197 | /** |
||
198 | * @param AbstractGenerator $generator |
||
199 | * @param $allowedRoutes |
||
200 | * @param $routePrefix |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes, $routePrefix) |
||
219 | |||
220 | /** |
||
221 | * @param $route |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | private function isValidRoute($route) |
||
229 | |||
230 | /** |
||
231 | * Generate Postman collection JSON file |
||
232 | * |
||
233 | * @param Collection $routes |
||
234 | * @return string |
||
235 | */ |
||
236 | private function generatePostmanCollection(Collection $routes) |
||
241 | } |
||
242 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.