|
@@ -20,11 +20,12 @@ class GetFromDocBlocks extends Strategy
|
|
|
|
|
|
public function getMetadataFromDocBlock(DocBlock $methodDocBlock, DocBlock $classDocBlock): array
|
|
|
{
|
|
|
- [$routeGroupName, $routeGroupDescription, $routeTitle] = $this->getRouteGroupDescriptionAndTitle($methodDocBlock, $classDocBlock);
|
|
|
+ [$routeGroupName, $routeGroupDescription, $routeTitle] = $this->getEndpointGroupDetails($methodDocBlock, $classDocBlock);
|
|
|
|
|
|
return [
|
|
|
'groupName' => $routeGroupName,
|
|
|
'groupDescription' => $routeGroupDescription,
|
|
|
+ 'subgroup' => $this->getEndpointSubGroup($methodDocBlock, $classDocBlock),
|
|
|
'title' => $routeTitle ?: $methodDocBlock->getShortDescription(),
|
|
|
'description' => $methodDocBlock->getLongDescription()->getContents(),
|
|
|
'authenticated' => $this->getAuthStatusFromDocBlock($methodDocBlock, $classDocBlock),
|
|
@@ -49,46 +50,41 @@ class GetFromDocBlocks extends Strategy
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param DocBlock $methodDocBlock
|
|
|
- * @param DocBlock $controllerDocBlock
|
|
|
- *
|
|
|
* @return array The route group name, the group description, and the route title
|
|
|
*/
|
|
|
- protected function getRouteGroupDescriptionAndTitle(DocBlock $methodDocBlock, DocBlock $controllerDocBlock)
|
|
|
+ protected function getEndpointGroupDetails(DocBlock $methodDocBlock, DocBlock $controllerDocBlock)
|
|
|
{
|
|
|
- // @group tag on the method overrides that on the controller
|
|
|
- if (!empty($methodDocBlock->getTags())) {
|
|
|
- foreach ($methodDocBlock->getTags() as $tag) {
|
|
|
- if ($tag->getName() === 'group') {
|
|
|
- $routeGroupParts = explode("\n", trim($tag->getContent()));
|
|
|
- $routeGroupName = array_shift($routeGroupParts);
|
|
|
- $routeGroupDescription = trim(implode("\n", $routeGroupParts));
|
|
|
-
|
|
|
- // If the route has no title (the methodDocBlock's "short description"),
|
|
|
- // we'll assume the routeGroupDescription is actually the title
|
|
|
- // Something like this:
|
|
|
- // /**
|
|
|
- // * Fetch cars. <-- This is route title.
|
|
|
- // * @group Cars <-- This is group name.
|
|
|
- // * APIs for cars. <-- This is group description (not required).
|
|
|
- // **/
|
|
|
- // VS
|
|
|
- // /**
|
|
|
- // * @group Cars <-- This is group name.
|
|
|
- // * Fetch cars. <-- This is route title, NOT group description.
|
|
|
- // **/
|
|
|
-
|
|
|
- // BTW, this is a spaghetti way of doing this.
|
|
|
- // It shall be refactored soon. Deus vult!💪
|
|
|
- if (empty($methodDocBlock->getShortDescription())) {
|
|
|
- return [$routeGroupName, '', $routeGroupDescription];
|
|
|
- }
|
|
|
-
|
|
|
- return [$routeGroupName, $routeGroupDescription, $methodDocBlock->getShortDescription()];
|
|
|
+ foreach ($methodDocBlock->getTags() as $tag) {
|
|
|
+ if ($tag->getName() === 'group') {
|
|
|
+ $routeGroupParts = explode("\n", trim($tag->getContent()));
|
|
|
+ $routeGroupName = array_shift($routeGroupParts);
|
|
|
+ $routeGroupDescription = trim(implode("\n", $routeGroupParts));
|
|
|
+
|
|
|
+ // If the route has no title (the methodDocBlock's "short description"),
|
|
|
+ // we'll assume the routeGroupDescription is actually the title
|
|
|
+ // Something like this:
|
|
|
+ // /**
|
|
|
+ // * Fetch cars. <-- This is route title.
|
|
|
+ // * @group Cars <-- This is group name.
|
|
|
+ // * APIs for cars. <-- This is group description (not required).
|
|
|
+ // **/
|
|
|
+ // VS
|
|
|
+ // /**
|
|
|
+ // * @group Cars <-- This is group name.
|
|
|
+ // * Fetch cars. <-- This is route title, NOT group description.
|
|
|
+ // **/
|
|
|
+
|
|
|
+ // BTW, this is a spaghetti way of doing this.
|
|
|
+ // It shall be refactored soon. Deus vult!💪
|
|
|
+ if (empty($methodDocBlock->getShortDescription())) {
|
|
|
+ return [$routeGroupName, '', $routeGroupDescription];
|
|
|
}
|
|
|
+
|
|
|
+ return [$routeGroupName, $routeGroupDescription, $methodDocBlock->getShortDescription()];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Fall back to the controller
|
|
|
foreach ($controllerDocBlock->getTags() as $tag) {
|
|
|
if ($tag->getName() === 'group') {
|
|
|
$routeGroupParts = explode("\n", trim($tag->getContent()));
|
|
@@ -101,4 +97,21 @@ class GetFromDocBlocks extends Strategy
|
|
|
|
|
|
return [$this->config->get('groups.default'), '', $methodDocBlock->getShortDescription()];
|
|
|
}
|
|
|
+
|
|
|
+ protected function getEndpointSubGroup(DocBlock $methodDocBlock, DocBlock $controllerDocBlock): ?string
|
|
|
+ {
|
|
|
+ foreach ($methodDocBlock->getTags() as $tag) {
|
|
|
+ if ($tag->getName() === 'subgroup') {
|
|
|
+ return trim($tag->getContent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($controllerDocBlock->getTags() as $tag) {
|
|
|
+ if ($tag->getName() === 'subgroup') {
|
|
|
+ return trim($tag->getContent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|