Total Complexity | 13 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | class Loader implements LoaderInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var AnnotationReader |
||
22 | */ |
||
23 | private $annotationReader; |
||
24 | /** |
||
25 | * @var StructureAnnotationListenerInterface[] |
||
26 | */ |
||
27 | private $classListeners = []; |
||
28 | /** |
||
29 | * @var PropertyAnnotationListenerInterface[] |
||
30 | */ |
||
31 | private $propertyListeners = []; |
||
32 | |||
33 | /** |
||
34 | * @param AnnotationReader $annotationReader |
||
35 | */ |
||
36 | public function __construct(AnnotationReader $annotationReader = null) |
||
37 | { |
||
38 | $this->annotationReader = $annotationReader ?: new AnnotationReader(); |
||
39 | $this->registerLoaders(); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param string $className |
||
44 | * @return bool |
||
45 | */ |
||
46 | public function exists(string $className): bool |
||
53 | } |
||
54 | |||
55 | public function load(string $className): ?DescriptorInterface |
||
56 | { |
||
57 | $className = Classes::normalizeAbsoluteName($className); |
||
58 | if (!$this->exists($className)) { |
||
59 | return null; |
||
60 | } |
||
61 | $descriptor = new Descriptor($className, new Mapping(), new Indexing()); |
||
62 | $reflection = new ReflectionClass($className); |
||
63 | foreach ($this->annotationReader->getClassAnnotations($reflection) as $annotation) { |
||
64 | foreach ($this->classListeners as $listener) { |
||
65 | $listener->accept($reflection, $descriptor, $annotation); |
||
66 | } |
||
67 | } |
||
68 | foreach ($reflection->getProperties(~ReflectionProperty::IS_STATIC) as $property) { |
||
69 | if ($property->getDeclaringClass()->getName() !== $reflection->getName()) { |
||
70 | continue; |
||
71 | } |
||
72 | foreach ($this->annotationReader->getPropertyAnnotations($property) as $annotation) { |
||
73 | foreach ($this->propertyListeners as $listener) { |
||
74 | $listener->accept($property, $descriptor, $annotation); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | return $descriptor; |
||
79 | } |
||
80 | |||
81 | private function registerLoaders() |
||
85 | } |
||
86 | } |
||
87 |