|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Gedmo\Mapping\Driver; |
| 4 | + |
| 5 | +use Doctrine\Common\Annotations\Reader; |
| 6 | +use Gedmo\Mapping\Annotation\Annotation; |
| 7 | +use ReflectionClass; |
| 8 | +use ReflectionMethod; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Gediminas Morkevicius <[email protected]> |
| 12 | + * @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
| 13 | + * |
| 14 | + * @internal |
| 15 | + */ |
| 16 | +final class AttributeAnnotationReader implements Reader |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var Reader |
| 20 | + */ |
| 21 | + private $annotationReader; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var AttributeReader |
| 25 | + */ |
| 26 | + private $attributeReader; |
| 27 | + |
| 28 | + public function __construct(AttributeReader $attributeReader, Reader $annotationReader) |
| 29 | + { |
| 30 | + $this->attributeReader = $attributeReader; |
| 31 | + $this->annotationReader = $annotationReader; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @return Annotation[] |
| 36 | + */ |
| 37 | + public function getClassAnnotations(ReflectionClass $class): array |
| 38 | + { |
| 39 | + $annotations = $this->attributeReader->getClassAnnotations($class); |
| 40 | + |
| 41 | + if ([] !== $annotations) { |
| 42 | + return $annotations; |
| 43 | + } |
| 44 | + |
| 45 | + return $this->annotationReader->getClassAnnotations($class); |
| 46 | + } |
| 47 | + |
| 48 | + public function getClassAnnotation(ReflectionClass $class, $annotationName): ?Annotation |
| 49 | + { |
| 50 | + $annotation = $this->attributeReader->getClassAnnotation($class, $annotationName); |
| 51 | + |
| 52 | + if (null !== $annotation) { |
| 53 | + return $annotation; |
| 54 | + } |
| 55 | + |
| 56 | + return $this->annotationReader->getClassAnnotation($class, $annotationName); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return Annotation[] |
| 61 | + */ |
| 62 | + public function getPropertyAnnotations(\ReflectionProperty $property): array |
| 63 | + { |
| 64 | + $propertyAnnotations = $this->attributeReader->getPropertyAnnotations($property); |
| 65 | + |
| 66 | + if ([] !== $propertyAnnotations) { |
| 67 | + return $propertyAnnotations; |
| 68 | + } |
| 69 | + |
| 70 | + return $this->annotationReader->getPropertyAnnotations($property); |
| 71 | + } |
| 72 | + |
| 73 | + public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName): ?Annotation |
| 74 | + { |
| 75 | + $annotation = $this->attributeReader->getPropertyAnnotation($property, $annotationName); |
| 76 | + |
| 77 | + if (null !== $annotation) { |
| 78 | + return $annotation; |
| 79 | + } |
| 80 | + |
| 81 | + return $this->annotationReader->getPropertyAnnotation($property, $annotationName); |
| 82 | + } |
| 83 | + |
| 84 | + public function getMethodAnnotations(ReflectionMethod $method) |
| 85 | + { |
| 86 | + throw new \BadMethodCallException('Not implemented'); |
| 87 | + } |
| 88 | + |
| 89 | + public function getMethodAnnotation(ReflectionMethod $method, $annotationName) |
| 90 | + { |
| 91 | + throw new \BadMethodCallException('Not implemented'); |
| 92 | + } |
| 93 | +} |
0 commit comments