Get Property Annotation

@param \ReflectionProperty $property
@param string              $annotationClass
@param AnnotationReader    $reader

@return null|object
426895
public static function getPropertyAnnotation(\ReflectionProperty $property, $annotationClass, AnnotationReader $reader)
    {
        return $reader->getPropertyAnnotation($property, $annotationClass);
    }
375867
public static function getPropertiesAnnotations($className, $annotationClassName = null)
    {
        if(null === $annotationClassName)
        {
            return static::$annotations[$className]['Properties'] ?? [];
        }
        $result = [];
        foreach(static::$annotations[$className]['Properties'] ?? [] as $propertyName => $annotations)
        {
            foreach($annotations as $annotation)
            {
                if($annotation instanceof $annotationClassName)
                {
                    $result[$propertyName][] = $annotation;
                }
            }
        }
        return $result;
    }
214003
public function getPropertyAnnotation(\ReflectionProperty $property)
    {
        $annot = $this->reader->getPropertyAnnotation($property, '\Represent\Annotations\Property');

        if (!$annot) {
            return false;
        }

        return $annot;
    }
1218363
private function readPrivateProperty($object, string $property)
    {
        $reflectionClass = new \ReflectionClass($object);
        $reflectionProperty = null;
        do {
            if ($reflectionClass->hasProperty($property)) {
                $reflectionProperty = $reflectionClass->getProperty($property);
            }
            $reflectionClass = $reflectionClass->getParentClass();
        } while ($reflectionClass);

        if ($reflectionProperty === null) {
            throw new \InvalidArgumentException("Unable to find property '".$property.'" in object of class '.get_class($object).". Please check your @URL annotation.");
        }

        $reflectionProperty->setAccessible(true);
        return $reflectionProperty->getValue($object);
    }
920837
public function getIdentifier($entity)
    {
        $id = $this->getPropertiesByType($entity, self::FIELD_IDENTIFIER_CLASS);

        if (count($id) == 0) {
            throw new AnnotationReaderException('no identifer declared in entity ' . get_class($entity));
        }

        return reset($id);
    }
562828
public static function getPropertyAnnotations($className, $propertyName, $annotationClassName = null)
    {
        if(!isset(static::$annotations[$className]['Properties'][$propertyName]))
        {
            return [];
        }
        if(null === $annotationClassName)
        {
            return static::$annotations[$className]['Properties'][$propertyName];
        }
        else
        {
            $result = [];
            foreach(static::$annotations[$className]['Properties'][$propertyName] as $annotation)
            {
                if($annotation instanceof $annotationClassName)
                {
                    $result[] = $annotation;
                }
            }
            return $result;
        }
    }
625971
private function createGetter(Entity $entity, $property, $annotation)
    {
        if ($annotation->getter === null) {
            $getter = new PropertyGetter($entity, $property);
        } else {
            if ($annotation->getter === true) {
                $methodName = 'get' . ucfirst($property);
            } else {
                $methodName = $annotation->getter;
            }
            $getter = new MethodGetter($entity, $methodName);
        }

        return $getter;
    }
74890
private function convertReflectionPropertyToManyToOneAssociationMetadata(
        ReflectionProperty $reflectionProperty,
        array $propertyAnnotations,
        Mapping\ClassMetadata $classMetadata
    ) {
        $className      = $classMetadata->getClassName();
        $fieldName      = $reflectionProperty->getName();
        $manyToOneAnnot = $propertyAnnotations[Annotation\ManyToOne::class];

        if ($manyToOneAnnot->targetEntity === null) {
            throw Mapping\MappingException::missingTargetEntity($fieldName);
        }

        $assocMetadata = new Mapping\ManyToOneAssociationMetadata($fieldName);
        $targetEntity  = $manyToOneAnnot->targetEntity;

        $assocMetadata->setSourceEntity($className);
        $assocMetadata->setTargetEntity($targetEntity);
        $assocMetadata->setCascade($this->getCascade($className, $fieldName, $manyToOneAnnot->cascade));
        $assocMetadata->setFetchMode($this->getFetchMode($className, $manyToOneAnnot->fetch));

        if (! empty($manyToOneAnnot->inversedBy)) {
            $assocMetadata->setInversedBy($manyToOneAnnot->inversedBy);
        }

        // Check for Id
        if (isset($propertyAnnotations[Annotation\Id::class])) {
            $assocMetadata->setPrimaryKey(true);
        }

        // Check for Cache
        if (isset($propertyAnnotations[Annotation\Cache::class])) {
            $cacheAnnot    = $propertyAnnotations[Annotation\Cache::class];
            $cacheMetadata = $this->convertCacheAnnotationToCacheMetadata($cacheAnnot, $classMetadata, $fieldName);

            $assocMetadata->setCache($cacheMetadata);
        }

        // Check for JoinColumn/JoinColumns annotations
        switch (true) {
            case isset($propertyAnnotations[Annotation\JoinColumn::class]):
                $joinColumnAnnot = $propertyAnnotations[Annotation\JoinColumn::class];
                $joinColumn      = $this->convertJoinColumnAnnotationToJoinColumnMetadata(
                    $reflectionProperty,
                    $joinColumnAnnot,
                    $classMetadata
                );

                $assocMetadata->addJoinColumn($joinColumn);

                break;

            case isset($propertyAnnotations[Annotation\JoinColumns::class]):
                $joinColumnsAnnot = $propertyAnnotations[Annotation\JoinColumns::class];

                foreach ($joinColumnsAnnot->value as $joinColumnAnnot) {
                    $joinColumn = $this->convertJoinColumnAnnotationToJoinColumnMetadata(
                        $reflectionProperty,
                        $joinColumnAnnot,
                        $classMetadata
                    );

                    $assocMetadata->addJoinColumn($joinColumn);
                }

                break;
        }

        return $assocMetadata;
    }
1360591
public static function readMethod( $method , $annotation = null ) {

		$ref = $method instanceof ReflectionMethod ? $method : new ReflectionMethod( $method[0] , $method[1] );

		return $annotation ? static::reader()->getMethodAnnotation( $ref , $annotation ) : static::reader()->getMethodAnnotations( $ref );

	}
179967
private function buildRouteDefinition(CachedReader $reader, \ReflectionClass $controllerReflClass)
    {
        $routeDefinitions = [];

        if ($controllerReflClass->isInstantiable()) {
            $annotations = $reader->getClassAnnotations($controllerReflClass);
            foreach ($annotations as $annotation) {
                if ($annotation instanceof Route) {
                    $annotation->controller = $controllerReflClass->getName();
                    $this->autoDetectEntity($annotation);
                    $routeDefinitions[] = (array)$annotation;
                }
            }

            foreach ($controllerReflClass->getMethods() as $method) {
                $annotations = $reader->getMethodAnnotations($method);
                foreach ($annotations as $annotation) {
                    if ($annotation instanceof Route) {
                        $annotation->controller = $controllerReflClass->getName();
                        $annotation->method = $method->getName();
                        $this->autoDetectEntity($annotation);
                        $routeDefinitions[] = (array)$annotation;
                    }
                }
            }
        }

        return $routeDefinitions;
    }
356283
private function readProperty($property, $metadata)
    {
        $reflClass = $metadata->getReflectionClass();
        
        // Skip if this property is not from this class
        if ($property->getDeclaringClass()->getName()
            != $metadata->getClassName()
        ) {
            return;
        }

        //Iterate over all annotations
        foreach($this->reader->getPropertyAnnotations($property) as $rule) {

            //Skip is its not a rule
            if ( ! $rule instanceof Rules\Rule ) continue;
            
            //Add Rule
            $metadata->addPropertyRule($property->getName(), $rule);

        }

    }
989846
public function parseProp(\ReflectionClass $ref, \ReflectionProperty $prop)
    {
        $annotations = $this->reader->getPropertyAnnotations($prop);
        if($this->checkAnnotations($annotations))
        {
            $this->data[$ref->getName()]['prop'][$prop->getName()] = $this->fileMap[$ref->getFileName()][$ref->getName()]['prop'][$prop->getName()] = &$annotations;
        }
    }
1305688
protected function createAttributeByProperty(AttributeAnnotation $annotation, \ReflectionProperty $property): Attribute
    {
        $name = ($annotation->name === null)
            ? $property->getName()
            : $annotation->name;

        $getter = ($annotation->getter === null)
            ? $this->resolveGetter($property)
            : $annotation->getter;

        $setter = ($annotation->setter === null)
            ? $this->resolveSetter($property)
            : $annotation->setter;

        $attribute = new Attribute($name, $getter);
        $attribute->setPropertyName($property->getName());

        if ($setter !== null) {
            $attribute->setSetter($setter);
        }

        $this->processAttributeOptions($annotation, $attribute);

        return $attribute;
    }
170117
public function getAnnotations(\Reflector $Reflection)
    {
        $doc = $Reflection->getDocComment();
        if ($this->cache) {
            $key = $this->cache->getKey($doc);
            $ast = $this->cache->get($key);
            if (! $ast) {
                $ast = $this->parser->parse($doc);
                $this->cache->set($key, $ast);
            }
        } else {
            $ast = $this->parser->parse($doc);
        }

        return new AnnotationsBag($ast);
    }
871847
private function convertReflectionPropertyToFieldMetadata(
        ReflectionProperty $reflectionProperty,
        array $propertyAnnotations,
        Mapping\ClassMetadata $classMetadata
    ) {
        $className    = $classMetadata->getClassName();
        $fieldName    = $reflectionProperty->getName();
        $columnAnnot  = $propertyAnnotations[Annotation\Column::class];
        $isVersioned  = isset($propertyAnnotations[Annotation\Version::class]);
        $isPrimaryKey = isset($propertyAnnotations[Annotation\Id::class]);

        if ($columnAnnot->type === null) {
            throw Mapping\MappingException::propertyTypeIsRequired($className, $fieldName);
        }

        if ($isVersioned && $isPrimaryKey) {
            throw Mapping\MappingException::cannotVersionIdField($className, $fieldName);
        }

        $columnName = empty($columnAnnot->name)
            ? $this->namingStrategy->propertyToColumnName($fieldName, $className)
            : $columnAnnot->name;

        $fieldMetadata = $isVersioned
            ? new Mapping\VersionFieldMetadata($fieldName)
            : new Mapping\FieldMetadata($fieldName);

        $fieldMetadata->setType(Type::getType($columnAnnot->type));
        $fieldMetadata->setColumnName($columnName);
        $fieldMetadata->setScale($columnAnnot->scale);
        $fieldMetadata->setPrecision($columnAnnot->precision);
        $fieldMetadata->setNullable($columnAnnot->nullable);
        $fieldMetadata->setUnique($columnAnnot->unique);

        // Check for Id
        if ($isPrimaryKey) {
            if ($fieldMetadata->getType()->canRequireSQLConversion()) {
                throw Mapping\MappingException::sqlConversionNotAllowedForPrimaryKeyProperties($className, $fieldMetadata);
            }

            $fieldMetadata->setPrimaryKey(true);
        }

        if (! empty($columnAnnot->columnDefinition)) {
            $fieldMetadata->setColumnDefinition($columnAnnot->columnDefinition);
        }

        if (! empty($columnAnnot->length)) {
            $fieldMetadata->setLength($columnAnnot->length);
        }

        // Assign default options
        $customOptions  = $columnAnnot->options ?? [];
        $defaultOptions = [];

        if ($isVersioned) {
            switch ($fieldMetadata->getTypeName()) {
                case 'integer':
                case 'bigint':
                case 'smallint':
                    $defaultOptions['default'] = 1;
                    break;

                case 'datetime':
                    $defaultOptions['default'] = 'CURRENT_TIMESTAMP';
                    break;

                default:
                    if (! isset($customOptions['default'])) {
                        throw Mapping\MappingException::unsupportedOptimisticLockingType($fieldMetadata->getType());
                    }
            }
        }

        $fieldMetadata->setOptions(array_merge($defaultOptions, $customOptions));

        return $fieldMetadata;
    }
1104328
public function getReader()
    {
        if ($this->reader) {
            return $this->reader;
        }

        $className = $this->getDoctrineAnnotationReaderClassName();

        $r = new ReflectionClass($className);

        $instance = $r->newInstance();

        if (!$instance instanceof DoctrineAnnotationsReaderInterface) {
            $errMsg = sprintf('Reader not implement %s', DoctrineAnnotationsReaderInterface::class);
            throw new Exception\InvalidDoctrineAnnotationsReaderException($errMsg);
        }

        $this->reader = $instance;

        return $this->reader;
    }
552002
public static function getAnnotationReader()
    {
        if (self::$annotationReader === null) {
            self::$annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
        }

        return self::$annotationReader;
    }