Doctrine\Common\Annotations\AnnotationReader::getPropertyAnnotation PHP Method

getPropertyAnnotation() public method

{@inheritDoc}
public getPropertyAnnotation ( ReflectionProperty $property, $annotationName )
$property ReflectionProperty
    public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
    {
        $annotations = $this->getPropertyAnnotations($property);
        foreach ($annotations as $annotation) {
            if ($annotation instanceof $annotationName) {
                return $annotation;
            }
        }
        return null;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function guessType($class, $property)
 {
     $metadata = $this->getClassMetadata($class);
     if (!$metadata->hasAssociation($property)) {
         return null;
     }
     $multiple = $metadata->isCollectionValuedAssociation($property);
     $annotationReader = new AnnotationReader();
     $associationMapping = $metadata->getAssociationMapping($property);
     $associationMetadata = $this->getClassMetadata($associationMapping['targetEntity']);
     if (null === $annotationReader->getClassAnnotation($associationMetadata->getReflectionClass(), static::TREE_ANNOTATION)) {
         return null;
     }
     $levelProperty = null;
     $parentProperty = null;
     foreach ($associationMetadata->getReflectionProperties() as $property) {
         if ($annotationReader->getPropertyAnnotation($property, static::TREE_LEVEL_ANNOTATION)) {
             $levelProperty = $property->getName();
         }
         if ($annotationReader->getPropertyAnnotation($property, static::TREE_PARENT_ANNOTATION)) {
             $parentProperty = $property->getName();
         }
     }
     if (null === $levelProperty || null === $parentProperty) {
         return null;
     }
     return new TypeGuess('tree_choice', ['class' => $associationMapping['targetEntity'], 'multiple' => $multiple, 'level_property' => $levelProperty, 'parent_property' => $parentProperty], Guess::VERY_HIGH_CONFIDENCE);
 }
All Usage Examples Of Doctrine\Common\Annotations\AnnotationReader::getPropertyAnnotation