vendor/gedmo/doctrine-extensions/src/Mapping/Driver/AttributeAnnotationReader.php line 60

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Doctrine Behavioral Extensions package.
  4.  * (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Gedmo\Mapping\Driver;
  9. use Doctrine\Common\Annotations\Reader;
  10. use Gedmo\Mapping\Annotation\Annotation;
  11. /**
  12.  * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  13.  *
  14.  * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15.  *
  16.  * @internal
  17.  */
  18. final class AttributeAnnotationReader implements Reader
  19. {
  20.     private Reader $annotationReader;
  21.     private AttributeReader $attributeReader;
  22.     public function __construct(AttributeReader $attributeReaderReader $annotationReader)
  23.     {
  24.         $this->attributeReader $attributeReader;
  25.         $this->annotationReader $annotationReader;
  26.     }
  27.     /**
  28.      * @phpstan-param \ReflectionClass<object> $class
  29.      *
  30.      * @return Annotation[]
  31.      */
  32.     public function getClassAnnotations(\ReflectionClass $class): array
  33.     {
  34.         $annotations $this->attributeReader->getClassAnnotations($class);
  35.         if ([] !== $annotations) {
  36.             return $annotations;
  37.         }
  38.         return $this->annotationReader->getClassAnnotations($class);
  39.     }
  40.     /**
  41.      * @param string $annotationName
  42.      *
  43.      * @phpstan-param \ReflectionClass<object> $class
  44.      * @phpstan-param class-string<T> $annotationName the name of the annotation
  45.      *
  46.      * @return T|null the Annotation or NULL, if the requested annotation does not exist
  47.      *
  48.      * @template T
  49.      */
  50.     public function getClassAnnotation(\ReflectionClass $class$annotationName)
  51.     {
  52.         $annotation $this->attributeReader->getClassAnnotation($class$annotationName);
  53.         return $annotation ?? $this->annotationReader->getClassAnnotation($class$annotationName);
  54.     }
  55.     /**
  56.      * @return Annotation[]
  57.      */
  58.     public function getPropertyAnnotations(\ReflectionProperty $property): array
  59.     {
  60.         $propertyAnnotations $this->attributeReader->getPropertyAnnotations($property);
  61.         if ([] !== $propertyAnnotations) {
  62.             return $propertyAnnotations;
  63.         }
  64.         return $this->annotationReader->getPropertyAnnotations($property);
  65.     }
  66.     /**
  67.      * @param class-string<T> $annotationName the name of the annotation
  68.      *
  69.      * @return T|null the Annotation or NULL, if the requested annotation does not exist
  70.      *
  71.      * @template T
  72.      */
  73.     public function getPropertyAnnotation(\ReflectionProperty $property$annotationName)
  74.     {
  75.         $annotation $this->attributeReader->getPropertyAnnotation($property$annotationName);
  76.         return $annotation ?? $this->annotationReader->getPropertyAnnotation($property$annotationName);
  77.     }
  78.     public function getMethodAnnotations(\ReflectionMethod $method): array
  79.     {
  80.         throw new \BadMethodCallException('Not implemented');
  81.     }
  82.     /**
  83.      * @return mixed
  84.      */
  85.     public function getMethodAnnotation(\ReflectionMethod $method$annotationName)
  86.     {
  87.         throw new \BadMethodCallException('Not implemented');
  88.     }
  89. }