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 | 11 | 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 | 11 | public function __construct(Reader $reader) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 11 | public function getDefinition(string $class): Definition |
|
82 | |||
83 | /** |
||
84 | * Create definition for given class |
||
85 | * |
||
86 | * @param string $class |
||
87 | * @return Definition |
||
88 | */ |
||
89 | 11 | public function createDefinition(string $class): Definition |
|
99 | |||
100 | /** |
||
101 | * Process properties of class |
||
102 | * |
||
103 | * @param \ReflectionClass $reflection |
||
104 | * @param Definition $definition |
||
105 | */ |
||
106 | 11 | protected function processProperties(\ReflectionClass $reflection, Definition $definition) |
|
122 | |||
123 | /** |
||
124 | * Process annotations of class |
||
125 | * |
||
126 | * @param \ReflectionClass $reflection |
||
127 | * @param Definition $definition |
||
128 | */ |
||
129 | 11 | protected function processClassAnnotations(\ReflectionClass $reflection, Definition $definition) |
|
147 | |||
148 | /** |
||
149 | * Handler resource identifier |
||
150 | * |
||
151 | * @param ResourceIdentifierAnnotation $annotation |
||
152 | * @param Definition $definition |
||
153 | */ |
||
154 | 6 | protected function handlerResourceIdentifier(ResourceIdentifierAnnotation $annotation, Definition $definition) |
|
160 | |||
161 | /** |
||
162 | * Process relationship |
||
163 | * |
||
164 | * @param RelationshipAnnotation $annotation |
||
165 | * @param \ReflectionProperty $property |
||
166 | * @return Relationship |
||
167 | */ |
||
168 | 8 | protected function createRelationship(RelationshipAnnotation $annotation, \ReflectionProperty $property): Relationship |
|
185 | |||
186 | /** |
||
187 | * Handler getter of related object |
||
188 | * |
||
189 | * @param RelationshipAnnotation $annotation |
||
190 | * @param Relationship $relationship |
||
191 | */ |
||
192 | 8 | protected function handleGetter(RelationshipAnnotation $annotation, Relationship $relationship) |
|
204 | |||
205 | /** |
||
206 | * Handle links |
||
207 | * |
||
208 | * @param RelationshipAnnotation $annotation |
||
209 | * @param Relationship $relationship |
||
210 | */ |
||
211 | 8 | protected function handleLinks(RelationshipAnnotation $annotation, Relationship $relationship) |
|
220 | |||
221 | /** |
||
222 | * Create link by link's annotation |
||
223 | * |
||
224 | * @param LinkAnnotation $annotation |
||
225 | * @return Link |
||
226 | */ |
||
227 | 7 | protected function createLink(LinkAnnotation $annotation): Link |
|
244 | |||
245 | /** |
||
246 | * Handle control of data-section |
||
247 | * |
||
248 | * @param RelationshipAnnotation $annotation |
||
249 | * @param Relationship $relationship |
||
250 | */ |
||
251 | 8 | protected function handleDataControl(RelationshipAnnotation $annotation, Relationship $relationship) |
|
256 | |||
257 | /** |
||
258 | * Resolve type of relationship |
||
259 | * |
||
260 | * @param RelationshipAnnotation $annotation |
||
261 | * @return int |
||
262 | */ |
||
263 | 8 | protected function resolveType(RelationshipAnnotation $annotation): int |
|
275 | } |