|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Mpociot\ApiDoc\Tools;
|
|
|
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
use Illuminate\Routing\Route;
|
|
|
use Mpociot\ApiDoc\Tools\ResponseStrategies\ResponseTagStrategy;
|
|
|
use Mpociot\ApiDoc\Tools\ResponseStrategies\ResponseCallStrategy;
|
|
@@ -10,6 +11,9 @@ use Mpociot\ApiDoc\Tools\ResponseStrategies\TransformerTagsStrategy;
|
|
|
|
|
|
class ResponseResolver
|
|
|
{
|
|
|
+ /**
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
public static $strategies = [
|
|
|
ResponseTagStrategy::class,
|
|
|
TransformerTagsStrategy::class,
|
|
@@ -22,23 +26,48 @@ class ResponseResolver
|
|
|
*/
|
|
|
private $route;
|
|
|
|
|
|
+ /**
|
|
|
+ * @param Route $route
|
|
|
+ */
|
|
|
public function __construct(Route $route)
|
|
|
{
|
|
|
$this->route = $route;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array $tags
|
|
|
+ * @param array $routeProps
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
private function resolve(array $tags, array $routeProps)
|
|
|
{
|
|
|
$response = null;
|
|
|
+
|
|
|
foreach (static::$strategies as $strategy) {
|
|
|
$strategy = new $strategy();
|
|
|
+
|
|
|
+ /** @var JsonResponse|array|null $response */
|
|
|
$response = $strategy($this->route, $tags, $routeProps);
|
|
|
+
|
|
|
if (! is_null($response)) {
|
|
|
- return $this->getResponseContent($response);
|
|
|
+ if (is_array($response)) {
|
|
|
+ return array_map(function (JsonResponse $response) {
|
|
|
+ return ['status' => $response->getStatusCode(), 'content' => $this->getResponseContent($response)];
|
|
|
+ }, $response);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [['status' => $response->getStatusCode(), 'content' => $this->getResponseContent($response)]];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $route
|
|
|
+ * @param $tags
|
|
|
+ * @param $routeProps
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public static function getResponse($route, $tags, $routeProps)
|
|
|
{
|
|
|
return (new static($route))->resolve($tags, $routeProps);
|