Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New annotations - response, request, openApi
- Loading branch information
1 parent
4c4f5db
commit 31d7008
Showing
15 changed files
with
645 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Apitte\Core\Annotation\Controller; | ||
|
||
use Doctrine\Common\Annotations\Annotation\Target; | ||
|
||
/** | ||
* @Annotation | ||
* @Target({"CLASS","METHOD"}) | ||
*/ | ||
final class OpenApi | ||
{ | ||
|
||
/** @var mixed[] */ | ||
private $data; | ||
|
||
/** | ||
* @param mixed[] $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Apitte\Core\Annotation\Controller; | ||
|
||
use Doctrine\Common\Annotations\Annotation\Target; | ||
|
||
/** | ||
* @Annotation | ||
* @Target("METHOD") | ||
*/ | ||
final class Request | ||
{ | ||
|
||
/** @var string|null */ | ||
private $description; | ||
|
||
/** @var string|null */ | ||
private $entity; | ||
|
||
/** @var bool */ | ||
private $required = false; | ||
|
||
/** | ||
* @param mixed[] $values | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
$this->description = $values['description'] ?? null; | ||
$this->description = $values['entity'] ?? null; | ||
if (isset($values['required']) && $values['required'] === true) { | ||
$this->required = true; | ||
} | ||
} | ||
|
||
public function getEntity(): ?string | ||
{ | ||
return $this->entity; | ||
} | ||
|
||
public function getDescription(): ?string | ||
{ | ||
return $this->description; | ||
} | ||
|
||
public function isRequired(): bool | ||
{ | ||
return $this->required; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Apitte\Core\Annotation\Controller; | ||
|
||
use Doctrine\Common\Annotations\Annotation\Target; | ||
use Doctrine\Common\Annotations\AnnotationException; | ||
|
||
/** | ||
* @Annotation | ||
* @Target("ANNOTATION") | ||
*/ | ||
final class Response | ||
{ | ||
|
||
/** @var string */ | ||
private $code = 'default'; | ||
|
||
/** @var string */ | ||
private $description; | ||
|
||
/** @var string|null */ | ||
private $entity; | ||
|
||
/** | ||
* @param mixed[] $values | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
if (!isset($values['description']) || empty($values['description'])) { | ||
throw new AnnotationException('Empty @Response description given'); | ||
} | ||
$this->code = $values['code'] ?? 'default'; | ||
$this->entity = $values['entity'] ?? null; | ||
$this->description = $values['description']; | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return $this->description; | ||
} | ||
|
||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function getEntity(): ?string | ||
{ | ||
return $this->entity; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Apitte\Core\Annotation\Controller; | ||
|
||
use Doctrine\Common\Annotations\Annotation\Target; | ||
use Doctrine\Common\Annotations\AnnotationException; | ||
|
||
/** | ||
* @Annotation | ||
* @Target("METHOD") | ||
*/ | ||
final class Responses | ||
{ | ||
|
||
/** @var Response[] */ | ||
private $responses = []; | ||
|
||
/** | ||
* @param mixed[] $values | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
if (isset($values['value'])) { | ||
if (empty($values['value'])) { | ||
throw new AnnotationException('Empty @Responses given'); | ||
} | ||
$this->responses = is_array($values['value']) ? $values['value'] : [$values['value']]; | ||
} else { | ||
throw new AnnotationException('No @Response given in @Responses'); | ||
} | ||
|
||
$takenCodes = []; | ||
/** @var Response $value */ | ||
foreach ($values['value'] as $value) { | ||
if (!isset($takenCodes[$value->getCode()])) { | ||
$takenCodes[$value->getCode()] = $value; | ||
} else { | ||
throw new AnnotationException(sprintf( | ||
'Multiple @Response annotations with "code=%s" given. Each response must have unique code.', | ||
$value->getCode() | ||
)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return Response[] | ||
*/ | ||
public function getResponses(): array | ||
{ | ||
return $this->responses; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
miranovyJan 30, 2019
Contributor