|
@@ -55,7 +55,7 @@ class UseApiResourceTags extends Strategy
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Get a response from the @apiResource/@apiResourceCollection and @apiResourceModel tags.
|
|
|
|
|
|
+ * Get a response from the @apiResource/@apiResourceCollection, @apiResourceModel and @apiResourceAdditional tags.
|
|
*
|
|
*
|
|
* @param Tag $apiResourceTag
|
|
* @param Tag $apiResourceTag
|
|
* @param Tag[] $allTags
|
|
* @param Tag[] $allTags
|
|
@@ -68,6 +68,7 @@ class UseApiResourceTags extends Strategy
|
|
{
|
|
{
|
|
[$statusCode, $apiResourceClass] = $this->getStatusCodeAndApiResourceClass($apiResourceTag);
|
|
[$statusCode, $apiResourceClass] = $this->getStatusCodeAndApiResourceClass($apiResourceTag);
|
|
[$model, $factoryStates, $relations, $pagination] = $this->getClassToBeTransformedAndAttributes($allTags);
|
|
[$model, $factoryStates, $relations, $pagination] = $this->getClassToBeTransformedAndAttributes($allTags);
|
|
|
|
+ $additionalData = $this->getAdditionalData($this->getApiResourceAdditionalTag($allTags));
|
|
$modelInstance = $this->instantiateApiResourceModel($model, $factoryStates, $relations);
|
|
$modelInstance = $this->instantiateApiResourceModel($model, $factoryStates, $relations);
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -107,6 +108,9 @@ class UseApiResourceTags extends Strategy
|
|
: $apiResourceClass::collection($list);
|
|
: $apiResourceClass::collection($list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Adding additional meta information for our resource response
|
|
|
|
+ $resource = $resource->additional($additionalData);
|
|
|
|
+
|
|
$uri = Utils::getUrlWithBoundParameters($endpointData->route->uri(), $endpointData->cleanUrlParameters);
|
|
$uri = Utils::getUrlWithBoundParameters($endpointData->route->uri(), $endpointData->cleanUrlParameters);
|
|
$method = $endpointData->route->methods()[0];
|
|
$method = $endpointData->route->methods()[0];
|
|
$request = Request::create($uri, $method);
|
|
$request = Request::create($uri, $method);
|
|
@@ -171,6 +175,19 @@ class UseApiResourceTags extends Strategy
|
|
return [$type, $states, $relations, $pagination];
|
|
return [$type, $states, $relations, $pagination];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns data for simulating JsonResource additional() function
|
|
|
|
+ *
|
|
|
|
+ * @param Tag|null $tag
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ private function getAdditionalData(?Tag $tag): array
|
|
|
|
+ {
|
|
|
|
+ return $tag
|
|
|
|
+ ? a::parseIntoAttributes($tag->getContent())
|
|
|
|
+ : [];
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param string $type
|
|
* @param string $type
|
|
*
|
|
*
|
|
@@ -229,4 +246,11 @@ class UseApiResourceTags extends Strategy
|
|
|
|
|
|
return Arr::first($apiResourceTags);
|
|
return Arr::first($apiResourceTags);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function getApiResourceAdditionalTag(array $tags): ?Tag
|
|
|
|
+ {
|
|
|
|
+ return Arr::first($tags, function ($tag) {
|
|
|
|
+ return ($tag instanceof Tag) && strtolower($tag->getName()) == 'apiresourceadditional';
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|