1 | <?php |
||
46 | abstract class Annotation implements AnnotationInterface |
||
47 | { |
||
48 | |||
49 | use Traits\MetaState; |
||
50 | |||
51 | protected $_properties = []; |
||
52 | protected $_publicProperties = []; |
||
53 | private static $_creationStack = []; |
||
54 | |||
55 | 51 | public function __construct($data = [], $target = false) |
|
56 | { |
||
57 | 51 | $reflection = new ReflectionClass($this); |
|
58 | 51 | $class = $reflection->name; |
|
59 | 51 | if (isset(self::$_creationStack[$class])) |
|
60 | 51 | { |
|
61 | throw new CircularReferenceException("Circular annotation reference on '$class'", E_USER_ERROR); |
||
62 | } |
||
63 | 51 | self::$_creationStack[$class] = true; |
|
64 | 51 | foreach ($data as $key => $value) |
|
65 | { |
||
66 | 44 | if ($reflection->hasProperty($key)) |
|
67 | 44 | { |
|
68 | 44 | $this->$key = $value; |
|
69 | 44 | } |
|
70 | 44 | $this->_properties[$key] = $value; |
|
71 | 51 | } |
|
72 | 51 | foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $field) |
|
73 | { |
||
74 | 51 | $this->_publicProperties[] = $field->name; |
|
75 | 51 | } |
|
76 | try |
||
77 | { |
||
78 | 51 | ConflictChecker::register($this); |
|
79 | 51 | TargetChecker::check($this, $target); |
|
80 | } |
||
81 | 51 | catch (UnexpectedValueException $ex) |
|
82 | { |
||
83 | 5 | throw $ex; |
|
84 | 51 | } finally |
|
85 | { |
||
86 | 51 | unset(self::$_creationStack[$class]); |
|
87 | 51 | } |
|
88 | 51 | } |
|
89 | |||
90 | public function getProperties() |
||
94 | |||
95 | /** |
||
96 | * Init annotation |
||
97 | */ |
||
98 | abstract public function init(); |
||
99 | |||
100 | /** |
||
101 | * Convert to array |
||
102 | * @return mixed[] |
||
103 | */ |
||
104 | public function toArray() |
||
113 | |||
114 | } |
||
115 |