1 | <?php |
||
17 | class AnnotationDefinitionProvider implements DefinitionProviderInterface |
||
18 | { |
||
19 | /** |
||
20 | * Pattern of "resource" parameter |
||
21 | */ |
||
22 | const RESOURCE_PATTERN = '~^(?<repository>[a-z_][a-z0-9_]*)\.(?<link>[a-z_][a-z0-9_]*)$~i'; |
||
23 | |||
24 | /** |
||
25 | * Annotation classes ha been registered. |
||
26 | * |
||
27 | * @var bool |
||
28 | */ |
||
29 | static private $annotationsRegistered = false; |
||
30 | |||
31 | /** |
||
32 | * Cache of created definitions |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | private $definitionCache = []; |
||
37 | |||
38 | /** |
||
39 | * Register annotation classes. |
||
40 | * Supports a medieval-aged way of "autoloading" for the Doctrine Annotation library. |
||
41 | */ |
||
42 | 13 | static protected function registerAnnotations() |
|
51 | |||
52 | /** |
||
53 | * Doctrine annotation reader |
||
54 | * |
||
55 | * @var Reader |
||
56 | */ |
||
57 | protected $reader; |
||
58 | |||
59 | /** |
||
60 | * AnnotationDefinitionProvider constructor. |
||
61 | * |
||
62 | * @param Reader $reader |
||
63 | */ |
||
64 | 13 | public function __construct(Reader $reader) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 13 | public function getDefinition(string $class): Definition |
|
84 | |||
85 | /** |
||
86 | * Create definition for given class |
||
87 | * |
||
88 | * @param \ReflectionClass $reflection |
||
89 | * @return Definition |
||
90 | */ |
||
91 | 13 | protected function createDefinition(\ReflectionClass $reflection): Definition |
|
106 | |||
107 | /** |
||
108 | * Process properties of class |
||
109 | * |
||
110 | * @param \ReflectionClass $reflection |
||
111 | * @param Definition $definition |
||
112 | */ |
||
113 | 13 | protected function processProperties(\ReflectionClass $reflection, Definition $definition) |
|
129 | |||
130 | /** |
||
131 | * Process annotations of class |
||
132 | * |
||
133 | * @param \ReflectionClass $reflection |
||
134 | * @param Definition $definition |
||
135 | */ |
||
136 | 13 | protected function processClassAnnotations(\ReflectionClass $reflection, Definition $definition) |
|
154 | |||
155 | /** |
||
156 | * Handler resource identifier |
||
157 | * |
||
158 | * @param ResourceIdentifierAnnotation $annotation |
||
159 | * @param Definition $definition |
||
160 | */ |
||
161 | 7 | protected function handlerResourceIdentifier(ResourceIdentifierAnnotation $annotation, Definition $definition) |
|
167 | |||
168 | /** |
||
169 | * Process relationship |
||
170 | * |
||
171 | * @param RelationshipAnnotation $annotation |
||
172 | * @param \ReflectionProperty $property |
||
173 | * @return Relationship |
||
174 | */ |
||
175 | 9 | protected function createRelationship(RelationshipAnnotation $annotation, \ReflectionProperty $property): Relationship |
|
192 | |||
193 | /** |
||
194 | * Handler getter of related object |
||
195 | * |
||
196 | * @param RelationshipAnnotation $annotation |
||
197 | * @param Relationship $relationship |
||
198 | */ |
||
199 | 9 | protected function handleGetter(RelationshipAnnotation $annotation, Relationship $relationship) |
|
211 | |||
212 | /** |
||
213 | * Handle links |
||
214 | * |
||
215 | * @param RelationshipAnnotation $annotation |
||
216 | * @param Relationship $relationship |
||
217 | */ |
||
218 | 9 | protected function handleLinks(RelationshipAnnotation $annotation, Relationship $relationship) |
|
227 | |||
228 | /** |
||
229 | * Create link by link's annotation |
||
230 | * |
||
231 | * @param LinkAnnotation $annotation |
||
232 | * @return Link |
||
233 | */ |
||
234 | 8 | protected function createLink(LinkAnnotation $annotation): Link |
|
251 | |||
252 | /** |
||
253 | * Handle control of data-section |
||
254 | * |
||
255 | * @param RelationshipAnnotation $annotation |
||
256 | * @param Relationship $relationship |
||
257 | */ |
||
258 | 9 | protected function handleDataControl(RelationshipAnnotation $annotation, Relationship $relationship) |
|
263 | |||
264 | /** |
||
265 | * Resolve type of relationship |
||
266 | * |
||
267 | * @param RelationshipAnnotation $annotation |
||
268 | * @return int |
||
269 | */ |
||
270 | 9 | protected function resolveType(RelationshipAnnotation $annotation): int |
|
282 | } |