@@ -43,7 +43,61 @@ abstract public function getMethods($route);
4343 *
4444 * @return array
4545 */
46- abstract public function processRoute ($ route , $ bindings = [], $ withResponse = true );
46+ public function processRoute ($ route , $ bindings = [], $ headers = [], $ withResponse = true )
47+ {
48+ $ routeDomain = $ route ->domain ();
49+ $ routeAction = $ route ->getAction ();
50+ $ routeGroup = $ this ->getRouteGroup ($ routeAction ['uses ' ]);
51+ $ routeDescription = $ this ->getRouteDescription ($ routeAction ['uses ' ]);
52+ $ showresponse = null ;
53+
54+ // set correct route domain
55+ $ headers [] = "HTTP_HOST: {$ routeDomain }" ;
56+ $ headers [] = "SERVER_NAME: {$ routeDomain }" ;
57+
58+ $ content = '' ;
59+ $ response = null ;
60+ $ docblockResponse = $ this ->getDocblockResponse ($ routeDescription ['tags ' ]);
61+ if ($ docblockResponse ) {
62+ // we have a response from the docblock ( @response )
63+ $ response = $ docblockResponse ;
64+ $ showresponse = true ;
65+ $ content = $ response ->getContent ();
66+ }
67+ if (! $ response ) {
68+ $ transformerResponse = $ this ->getTransformerResponse ($ routeDescription ['tags ' ]);
69+ if ($ transformerResponse ) {
70+ // we have a transformer response from the docblock ( @transformer || @transformercollection )
71+ $ response = $ transformerResponse ;
72+ $ showresponse = true ;
73+ $ content = $ response ->getContent ();
74+ }
75+ }
76+ if (! $ response && $ withResponse ) {
77+ try {
78+ $ response = $ this ->getRouteResponse ($ route , $ bindings , $ headers );
79+ if ($ response ->headers ->get ('Content-Type ' ) === 'application/json ' ) {
80+ $ content = json_decode ($ response ->getContent (), JSON_PRETTY_PRINT );
81+ } else {
82+ $ content = $ response ->getContent ();
83+ }
84+ } catch (\Exception $ e ) {
85+ dump ("Couldn't get response for route: " .implode (', ' , $ this ->getMethods ($ route )).'] ' .$ route ->uri ()."" , $ e );
86+ }
87+ }
88+
89+ return $ this ->getParameters ([
90+ 'id ' => md5 ($ this ->getUri ($ route ).': ' .implode ($ this ->getMethods ($ route ))),
91+ 'resource ' => $ routeGroup ,
92+ 'title ' => $ routeDescription ['short ' ],
93+ 'description ' => $ routeDescription ['long ' ],
94+ 'methods ' => $ this ->getMethods ($ route ),
95+ 'uri ' => $ this ->getUri ($ route ),
96+ 'parameters ' => [],
97+ 'response ' => $ content ,
98+ 'showresponse ' => $ showresponse ,
99+ ], $ routeAction , $ bindings );
100+ }
47101
48102 /**
49103 * Prepares / Disables route middlewares.
@@ -179,7 +233,7 @@ protected function addRouteModelBindings($route, $bindings)
179233 /**
180234 * @param \Illuminate\Routing\Route $route
181235 *
182- * @return string
236+ * @return array
183237 */
184238 protected function getRouteDescription ($ route )
185239 {
0 commit comments