1 | <?php |
||
16 | class AnnotationDefinitionProvider implements DefinitionProviderInterface |
||
17 | { |
||
18 | /** |
||
19 | * Pattern of "resource" parameter |
||
20 | */ |
||
21 | const RESOURCE_PATTERN = '~^(?<repository>[a-z_][a-z0-9_]*)\.(?<link>[a-z_][a-z0-9_]*)$~i'; |
||
22 | |||
23 | /** |
||
24 | * Annotation classes ha been registered. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | static private $annotationsRegistered = false; |
||
29 | |||
30 | /** |
||
31 | * Cache of created definitions |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | private $definitionCache = []; |
||
36 | |||
37 | /** |
||
38 | * Register annotation classes. |
||
39 | * Supports a medieval-aged way of "autoloading" for the Doctrine Annotation library. |
||
40 | */ |
||
41 | 7 | static protected function registerAnnotations() |
|
50 | |||
51 | /** |
||
52 | * Doctrine annotation reader |
||
53 | * |
||
54 | * @var Reader |
||
55 | */ |
||
56 | protected $reader; |
||
57 | |||
58 | /** |
||
59 | * AnnotationDefinitionProvider constructor. |
||
60 | * |
||
61 | * @param Reader $reader |
||
62 | */ |
||
63 | 7 | public function __construct(Reader $reader) |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 7 | public function getDefinition(string $class): Definition |
|
81 | |||
82 | /** |
||
83 | * Create definition for given class |
||
84 | * |
||
85 | * @param string $class |
||
86 | * @return Definition |
||
87 | */ |
||
88 | 7 | public function createDefinition(string $class): Definition |
|
98 | |||
99 | /** |
||
100 | * Process properties of class |
||
101 | * |
||
102 | * @param \ReflectionClass $reflection |
||
103 | * @param Definition $definition |
||
104 | */ |
||
105 | 7 | protected function processProperties(\ReflectionClass $reflection, Definition $definition) |
|
121 | |||
122 | /** |
||
123 | * Process annotations of class |
||
124 | * |
||
125 | * @param \ReflectionClass $reflection |
||
126 | * @param Definition $definition |
||
127 | */ |
||
128 | 7 | protected function processClassAnnotations(\ReflectionClass $reflection, Definition $definition) |
|
141 | |||
142 | /** |
||
143 | * Process relationship |
||
144 | * |
||
145 | * @param RelationshipAnnotation $annotation |
||
146 | * @param \ReflectionProperty $property |
||
147 | * @return Relationship |
||
148 | */ |
||
149 | 5 | protected function createRelationship(RelationshipAnnotation $annotation, \ReflectionProperty $property): Relationship |
|
170 | |||
171 | /** |
||
172 | * Handler getter of related object |
||
173 | * |
||
174 | * @param RelationshipAnnotation $annotation |
||
175 | * @param Relationship $relationship |
||
176 | */ |
||
177 | 5 | protected function handleGetter(RelationshipAnnotation $annotation, Relationship $relationship) |
|
189 | |||
190 | /** |
||
191 | * Handle identifier |
||
192 | * |
||
193 | * @param RelationshipAnnotation $annotation |
||
194 | * @param Relationship $relationship |
||
195 | */ |
||
196 | 5 | protected function handleIdentifier(RelationshipAnnotation $annotation, Relationship $relationship) |
|
210 | |||
211 | /** |
||
212 | * Handle links |
||
213 | * |
||
214 | * @param RelationshipAnnotation $annotation |
||
215 | * @param Relationship $relationship |
||
216 | */ |
||
217 | 5 | protected function handleLinks(RelationshipAnnotation $annotation, Relationship $relationship) |
|
226 | |||
227 | /** |
||
228 | * Create link by link's annotation |
||
229 | * |
||
230 | * @param LinkAnnotation $annotation |
||
231 | * @return Link |
||
232 | */ |
||
233 | 5 | protected function createLink(LinkAnnotation $annotation): Link |
|
250 | |||
251 | /** |
||
252 | * Resolve type of relationship |
||
253 | * |
||
254 | * @param RelationshipAnnotation $annotation |
||
255 | * @return int |
||
256 | */ |
||
257 | 5 | protected function resolveType(RelationshipAnnotation $annotation): int |
|
269 | } |