Skip to content

Commit

Permalink
Check entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix Šulc committed Aug 21, 2018
1 parent 885693a commit 6523e4a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Annotation/Controller/ResponseMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Apitte\Core\Annotation\Controller;

use Apitte\Core\Mapping\Response\IResponseEntity;
use Doctrine\Common\Annotations\Annotation\Target;
use Doctrine\Common\Annotations\AnnotationException;

Expand All @@ -20,10 +21,18 @@ final class ResponseMapper
*/
public function __construct(array $values)
{
if (!isset($values['entity'])) {
if (!isset($values['entity']) || empty($values['entity'])) {
throw new AnnotationException('Empty @ResponseMapper entity given');
}

if (!class_exists($values['entity'])) {
throw new AnnotationException(sprintf('@ResponseMapper entity "%s" does not exists', $values['entity']));
}

if (!isset(class_implements($values['entity'])[IResponseEntity::class])) {
throw new AnnotationException(sprintf('@ResponseMapper entity "%s" does not implements "%s"', $values['entity'], IResponseEntity::class));
}

$this->entity = $values['entity'];
}

Expand Down

0 comments on commit 6523e4a

Please sign in to comment.