33namespace Mpociot \ApiDoc \Commands ;
44
55use ReflectionClass ;
6+ use Illuminate \Routing \Route ;
67use Illuminate \Console \Command ;
78use Mpociot \Reflection \DocBlock ;
89use Illuminate \Support \Collection ;
9- use Illuminate \Support \Facades \Route ;
1010use Mpociot \Documentarian \Documentarian ;
1111use Mpociot \ApiDoc \Postman \CollectionWriter ;
1212use Mpociot \ApiDoc \Generators \DingoGenerator ;
1313use Mpociot \ApiDoc \Generators \LaravelGenerator ;
1414use Mpociot \ApiDoc \Generators \AbstractGenerator ;
15+ use Illuminate \Support \Facades \Route as RouteFacade ;
1516
1617class GenerateDocumentation extends Command
1718{
@@ -91,7 +92,7 @@ public function handle()
9192 if ($ this ->option ('router ' ) === 'laravel ' ) {
9293 foreach ($ routeDomains as $ routeDomain ) {
9394 foreach ($ routePrefixes as $ routePrefix ) {
94- $ parsedRoutes += $ this ->processLaravelRoutes ($ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware );
95+ $ parsedRoutes += $ this ->processRoutes ($ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware );
9596 }
9697 }
9798 } else {
@@ -215,6 +216,7 @@ private function getBindings()
215216 if (empty ($ bindings )) {
216217 return [];
217218 }
219+
218220 $ bindings = explode ('| ' , $ bindings );
219221 $ resultBindings = [];
220222 foreach ($ bindings as $ binding ) {
@@ -250,9 +252,9 @@ private function setUserToBeImpersonated($actAs)
250252 private function getRoutes ()
251253 {
252254 if ($ this ->option ('router ' ) === 'laravel ' ) {
253- return Route ::getRoutes ();
255+ return RouteFacade ::getRoutes ();
254256 } else {
255- return app ('Dingo\Api\Routing\Router ' )->getRoutes ()[ $ this -> option ( ' routePrefix ' )] ;
257+ return app ('Dingo\Api\Routing\Router ' )->getRoutes ();
256258 }
257259 }
258260
@@ -264,13 +266,14 @@ private function getRoutes()
264266 *
265267 * @return array
266268 */
267- private function processLaravelRoutes (AbstractGenerator $ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware )
269+ private function processRoutes (AbstractGenerator $ generator , array $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware )
268270 {
269- $ withResponse = $ this ->option ('noResponseCalls ' ) === false ;
271+ $ withResponse = $ this ->option ('noResponseCalls ' ) == false ;
270272 $ routes = $ this ->getRoutes ();
271273 $ bindings = $ this ->getBindings ();
272274 $ parsedRoutes = [];
273275 foreach ($ routes as $ route ) {
276+ /** @var Route $route */
274277 if (in_array ($ route ->getName (), $ allowedRoutes )
275278 || (str_is ($ routeDomain , $ generator ->getDomain ($ route ))
276279 && str_is ($ routePrefix , $ generator ->getUri ($ route )))
@@ -288,46 +291,12 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout
288291 return $ parsedRoutes ;
289292 }
290293
291- /**
292- * @param AbstractGenerator $generator
293- * @param $allowedRoutes
294- * @param $routeDomain
295- * @param $routePrefix
296- *
297- * @return array
298- */
299- private function processDingoRoutes (AbstractGenerator $ generator , $ allowedRoutes , $ routeDomain , $ routePrefix , $ middleware )
300- {
301- $ withResponse = $ this ->option ('noResponseCalls ' ) === false ;
302- $ routes = $ this ->getRoutes ();
303- $ bindings = $ this ->getBindings ();
304- $ parsedRoutes = [];
305- foreach ($ routes as $ route ) {
306- if (empty ($ allowedRoutes )
307- // TODO extract this into a method
308- || in_array ($ route ->getName (), $ allowedRoutes )
309- || (str_is ($ routeDomain , $ generator ->getDomain ($ route ))
310- && str_is ($ routePrefix , $ generator ->getUri ($ route )))
311- || in_array ($ middleware , $ route ->middleware ())
312- ) {
313- if ($ this ->isValidRoute ($ route ) && $ this ->isRouteVisibleForDocumentation ($ route ->getAction ()['uses ' ])) {
314- $ parsedRoutes [] = $ generator ->processRoute ($ route , $ bindings , $ this ->option ('header ' ), $ withResponse && in_array ('GET ' , $ generator ->getMethods ($ route )));
315- $ this ->info ('Processed route: [ ' .implode (', ' , $ generator ->getMethods ($ route )).'] ' .$ route ->uri ());
316- } else {
317- $ this ->warn ('Skipping route: [ ' .implode (', ' , $ generator ->getMethods ($ route )).'] ' .$ route ->uri ());
318- }
319- }
320- }
321-
322- return $ parsedRoutes ;
323- }
324-
325294 /**
326295 * @param $route
327296 *
328297 * @return bool
329298 */
330- private function isValidRoute ($ route )
299+ private function isValidRoute (Route $ route )
331300 {
332301 return ! is_callable ($ route ->getAction ()['uses ' ]) && ! is_null ($ route ->getAction ()['uses ' ]);
333302 }
0 commit comments