| 1 | <?php |
||
| 2 | |||
| 3 | namespace SimpleAnnotation; |
||
| 4 | |||
| 5 | use ReflectionException; |
||
| 6 | use SimpleAnnotation\Concerns\CacheInterface; |
||
| 7 | use SimpleAnnotation\Exceptions\EmptyClassException; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Class Annotation. |
||
| 11 | * |
||
| 12 | * @package SimpleAnnotation |
||
| 13 | */ |
||
| 14 | final class Annotation |
||
| 15 | {
|
||
| 16 | use AnnotationTrait; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 17 | |||
| 18 | /** |
||
| 19 | * Annotation constructor. |
||
| 20 | * |
||
| 21 | * @param object|string $class |
||
| 22 | * @param CacheInterface|null $cache |
||
| 23 | * @throws EmptyClassException |
||
| 24 | * @throws ReflectionException |
||
| 25 | */ |
||
| 26 | 27 | public function __construct($class, CacheInterface $cache = null) |
|
| 27 | {
|
||
| 28 | 27 | if (is_object($class)) {
|
|
| 29 | 26 | $declaredClass = get_class($class); |
|
| 30 | } else {
|
||
| 31 | 1 | $declaredClass = $class; |
|
| 32 | } |
||
| 33 | |||
| 34 | 27 | if (empty($declaredClass)) {
|
|
| 35 | 1 | throw new EmptyClassException(); |
|
| 36 | } |
||
| 37 | |||
| 38 | 26 | $this->reflectionClass = new \ReflectionClass($declaredClass); |
|
| 39 | 26 | $this->annotationParser = new AnnotationParser(); |
|
| 40 | 26 | $this->cache = $cache; |
|
| 41 | 26 | } |
|
| 42 | } |
||
| 43 |