@@ -55,37 +55,30 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons
5555 $ headers [] = "HTTP_HOST: {$ routeDomain }" ;
5656 $ headers [] = "SERVER_NAME: {$ routeDomain }" ;
5757
58- $ content = '' ;
5958 $ response = null ;
6059 $ docblockResponse = $ this ->getDocblockResponse ($ routeDescription ['tags ' ]);
6160 if ($ docblockResponse ) {
6261 // we have a response from the docblock ( @response )
6362 $ response = $ docblockResponse ;
6463 $ showresponse = true ;
65- $ content = $ response ->getContent ();
6664 }
6765 if (! $ response ) {
6866 $ transformerResponse = $ this ->getTransformerResponse ($ routeDescription ['tags ' ]);
6967 if ($ transformerResponse ) {
7068 // we have a transformer response from the docblock ( @transformer || @transformercollection )
7169 $ response = $ transformerResponse ;
7270 $ showresponse = true ;
73- $ content = $ response ->getContent ();
7471 }
7572 }
7673 if (! $ response && $ withResponse ) {
7774 try {
7875 $ 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- }
8476 } catch (\Exception $ e ) {
8577 dump ("Couldn't get response for route: " .implode (', ' , $ this ->getMethods ($ route )).'] ' .$ route ->uri ().'' , $ e );
8678 }
8779 }
8880
81+ $ content = $ this ->getResponseContent ($ response );
8982 return $ this ->getParameters ([
9083 'id ' => md5 ($ this ->getUri ($ route ).': ' .implode ($ this ->getMethods ($ route ))),
9184 'resource ' => $ routeGroup ,
@@ -665,4 +658,21 @@ protected function normalizeRule($rule)
665658 return $ rule ;
666659 }
667660 }
661+
662+ /**
663+ * @param $response
664+ * @return mixed
665+ */
666+ private function getResponseContent ($ response )
667+ {
668+ if (empty ($ response )) {
669+ return '' ;
670+ }
671+ if ($ response ->headers ->get ('Content-Type ' ) === 'application/json ' ) {
672+ $ content = json_decode ($ response ->getContent (), JSON_PRETTY_PRINT );
673+ } else {
674+ $ content = $ response ->getContent ();
675+ }
676+ return $ content ;
677+ }
668678}
0 commit comments