Skip to content

Commit

Permalink
Merge ce57a4e into 821d9be
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jun 20, 2019
2 parents 821d9be + ce57a4e commit bc6b5e3
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Blocks/Controllers.php
Expand Up @@ -2,6 +2,7 @@

namespace SoliDry\Blocks;

use SoliDry\Documentation\Documentation;
use SoliDry\Extension\BaseController;
use SoliDry\Helpers\Classes;
use SoliDry\Helpers\Console;
Expand All @@ -15,8 +16,11 @@
*/
class Controllers extends Documentation implements ControllersInterface
{

/**
* Creates the DefaultController and outputs path to the console
*
* @throws \ReflectionException
*/
public function createDefault(): void
{
Expand Down Expand Up @@ -66,6 +70,8 @@ protected function setContent()

/**
* Sets the DefaultController content
*
* @throws \ReflectionException
*/
private function setDefaultContent()
{
Expand Down
@@ -1,8 +1,9 @@
<?php

namespace SoliDry\Blocks;
namespace SoliDry\Documentation;

use SoliDry\ApiGenerator;
use SoliDry\Blocks\ContentManager;
use SoliDry\Controllers\BaseCommand;
use SoliDry\Helpers\Classes;
use SoliDry\Types\ApiInterface;
Expand All @@ -20,7 +21,7 @@
abstract class Documentation
{

use ContentManager;
use ContentManager, RelationsDoc;

protected $generator;
protected $sourceCode = '';
Expand All @@ -37,7 +38,7 @@ public function __construct($generator)
$this->className = Classes::getClassName($this->generator->objectName);
}

protected function setDefaultDocs()
protected function setDefaultDocs(): void
{
$this->setComment(DefaultInterface::METHOD_START);

Expand Down Expand Up @@ -146,9 +147,22 @@ protected function setControllersDocs(): void

$this->setDelete();

$this->setRelated();

$this->setRelations();

$this->setCreateRelation();

$this->setUpdateRelation();

$this->setDeleteRelation();

$this->setComment(DefaultInterface::METHOD_END);
}

/**
* Sets OAS documentation for an index method
*/
private function setIndex(): void
{
$this->openComment();
Expand Down Expand Up @@ -180,7 +194,7 @@ private function setIndex(): void
'in' => '"query"',
'name' => '"limit"',
'required' => 'false',
]);
], 'integer');

$this->setParameter([
'in' => '"query"',
Expand Down Expand Up @@ -217,6 +231,9 @@ private function setIndex(): void
$this->setNewLines();
}

/**
* Sets OAS documentation for a view method
*/
private function setView(): void
{
$this->openComment();
Expand Down Expand Up @@ -254,6 +271,9 @@ private function setView(): void
$this->setNewLines();
}

/**
* Sets OAS documentation for a create method
*/
private function setCreate(): void
{
$this->openComment();
Expand All @@ -279,6 +299,9 @@ private function setCreate(): void
$this->setNewLines();
}

/**
* Sets OAS documentation for an update method
*/
private function setUpdate(): void
{
$this->openComment();
Expand All @@ -304,6 +327,9 @@ private function setUpdate(): void
$this->setNewLines();
}

/**
* Sets OAS documentation for a delete method
*/
private function setDelete(): void
{
$this->openComment();
Expand Down
222 changes: 222 additions & 0 deletions src/Documentation/RelationsDoc.php
@@ -0,0 +1,222 @@
<?php

namespace SoliDry\Documentation;

use SoliDry\Types\DefaultInterface;
use SoliDry\Types\DocumentationInterface;
use SoliDry\Types\PhpInterface;

trait RelationsDoc
{
/**
* Sets OAS documentation for a related method
*/
private function setRelated(): void
{
$this->openComment();

$this->setStarredComment(DocumentationInterface::OA_GET . PhpInterface::OPEN_PARENTHESES);

$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/{related}",', 1, 1);

$this->setStarredComment('summary="Get ' . $this->generator->objectName . ' related objects",', 1, 1);

$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
. '"},', 1, 1);

$this->setParameter([
'in' => '"query"',
'name' => '"data"',
'required' => 'false',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"id"',
'required' => 'true',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"related"',
'required' => 'true',
]);

$this->setResponse([
'response' => '200',
'description' => '""',
]);

$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);

$this->closeComment();
$this->setNewLines();
}

/**
* Sets OAS documentation for getting relations method
*/
private function setRelations(): void
{
$this->openComment();

$this->setStarredComment(DocumentationInterface::OA_GET . PhpInterface::OPEN_PARENTHESES);

$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);

$this->setStarredComment('summary="Get ' . $this->generator->objectName . ' relations objects",', 1, 1);

$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
. '"},', 1, 1);

$this->setParameter([
'in' => '"query"',
'name' => '"data"',
'required' => 'false',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"id"',
'required' => 'true',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"relations"',
'required' => 'true',
]);

$this->setResponse([
'response' => '200',
'description' => '""',
]);

$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);

$this->closeComment();
$this->setNewLines();
}

/**
* Sets OAS documentation for creating relation method
*/
private function setCreateRelation(): void
{
$this->openComment();

$this->setStarredComment(DocumentationInterface::OA_POST . PhpInterface::OPEN_PARENTHESES);

$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);

$this->setStarredComment('summary="Create ' . $this->generator->objectName . ' relation object",', 1, 1);

$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
. '"},', 1, 1);

$this->setParameter([
'in' => '"path"',
'name' => '"id"',
'required' => 'true',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"relations"',
'required' => 'true',
]);

$this->setResponse([
'response' => '200',
'description' => '""',
]);

$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);

$this->closeComment();
$this->setNewLines();
}

/**
* Sets OAS documentation for updating relation method
*/
private function setUpdateRelation(): void
{
$this->openComment();

$this->setStarredComment(DocumentationInterface::OA_PATCH . PhpInterface::OPEN_PARENTHESES);

$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);

$this->setStarredComment('summary="Update ' . $this->generator->objectName . ' relation object",', 1, 1);

$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
. '"},', 1, 1);

$this->setParameter([
'in' => '"path"',
'name' => '"id"',
'required' => 'true',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"relations"',
'required' => 'true',
]);

$this->setResponse([
'response' => '200',
'description' => '""',
]);

$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);

$this->closeComment();
$this->setNewLines();
}

/**
* Sets OAS documentation for deleting relation method
*/
private function setDeleteRelation(): void
{
$this->openComment();

$this->setStarredComment(DocumentationInterface::OA_DELETE . PhpInterface::OPEN_PARENTHESES);

$this->setStarredComment('path="' . PhpInterface::SLASH . $this->generator->version . PhpInterface::SLASH
. strtolower($this->generator->objectName) . PhpInterface::SLASH . '{id}/relationships/{relations}",', 1, 1);

$this->setStarredComment('summary="Delete ' . $this->generator->objectName . ' relation object",', 1, 1);

$this->setStarredComment('tags={"' . $this->generator->objectName . DefaultInterface::CONTROLLER_POSTFIX
. '"},', 1, 1);

$this->setParameter([
'in' => '"path"',
'name' => '"id"',
'required' => 'true',
]);

$this->setParameter([
'in' => '"path"',
'name' => '"relations"',
'required' => 'true',
]);

$this->setResponse([
'response' => '200',
'description' => '""',
]);

$this->setStarredComment(PhpInterface::CLOSE_PARENTHESES);

$this->closeComment();
$this->setNewLines();
}
}

0 comments on commit bc6b5e3

Please sign in to comment.