當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Reader::getPropertyAnnotations方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Annotations\Reader::getPropertyAnnotations方法的典型用法代碼示例。如果您正苦於以下問題:PHP Reader::getPropertyAnnotations方法的具體用法?PHP Reader::getPropertyAnnotations怎麽用?PHP Reader::getPropertyAnnotations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Annotations\Reader的用法示例。


在下文中一共展示了Reader::getPropertyAnnotations方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadMetadata

 /**
  * {@inheritDoc}
  */
 public function loadMetadata($class)
 {
     // Try get object annotation from class
     $objectAnnotation = null;
     $classAnnotations = Reflection::loadClassAnnotations($this->reader, $class, true);
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof ObjectAnnotation) {
             if ($objectAnnotation) {
                 throw new \RuntimeException(sprintf('Many @Transformer\\Object annotation in class "%s".', $class));
             }
             $objectAnnotation = $classAnnotation;
         }
     }
     if (!$objectAnnotation) {
         throw new TransformAnnotationNotFoundException(sprintf('Not found @Object annotations in class "%s".', $class));
     }
     // Try get properties annotations
     $properties = [];
     $classProperties = Reflection::getClassProperties($class, true);
     foreach ($classProperties as $classProperty) {
         $propertyAnnotations = $this->reader->getPropertyAnnotations($classProperty);
         foreach ($propertyAnnotations as $propertyAnnotation) {
             if ($propertyAnnotation instanceof PropertyAnnotation) {
                 $property = new PropertyMetadata($propertyAnnotation->propertyName ?: $classProperty->getName(), $propertyAnnotation->groups, $propertyAnnotation->shouldTransform, $propertyAnnotation->expressionValue);
                 $properties[$classProperty->getName()] = $property;
             }
         }
     }
     return new ObjectMetadata($objectAnnotation->transformedClass, $properties);
 }
開發者ID:Gtvar,項目名稱:FivePercent-ModelTransformer,代碼行數:33,代碼來源:MetadataFactory.php

示例2: loadMetadataForClass

 /**
  * Load metadata class
  *
  * @param \ReflectionClass $class
  * @return ClassMetadata
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $classMetadata = new ClassMetadata($class->name);
     $classMetadata->fileResources[] = $class->getFileName();
     foreach ($this->reader->getClassAnnotations($class) as $annotation) {
         if ($annotation instanceof NamespaceNode) {
             $classMetadata->addGraphNamespace($annotation);
         }
         if ($annotation instanceof GraphNode) {
             $classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value));
         }
     }
     foreach ($class->getProperties() as $property) {
         foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof GraphNode) {
                 $classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name));
             }
         }
     }
     foreach ($class->getMethods() as $method) {
         foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
             if ($annotation instanceof GraphNode) {
                 $classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name));
             }
         }
     }
     return $classMetadata;
 }
開發者ID:novaway,項目名稱:open-graph,代碼行數:34,代碼來源:AnnotationDriver.php

示例3: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $annotations = $this->reader->getClassAnnotations($class);
     if (0 === count($annotations)) {
         return null;
     }
     $classMetadata = new ClassMetadata($class->getName());
     $classMetadata->fileResources[] = $class->getFileName();
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Annotation\Resource) {
             // auto transform type from class name
             if (!$annotation->type) {
                 $annotation->type = String::dasherize($class->getShortName());
             }
             $classMetadata->setResource(new Resource($annotation->type, $annotation->showLinkSelf));
         }
     }
     $classProperties = $class->getProperties();
     foreach ($classProperties as $property) {
         $annotations = $this->reader->getPropertyAnnotations($property);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Annotation\Id) {
                 $classMetadata->setIdField($property->getName());
             } else {
                 if ($annotation instanceof Annotation\Relationship) {
                     $classMetadata->addRelationship(new Relationship($property->getName(), $annotation->includeByDefault, $annotation->showLinkSelf, $annotation->showLinkRelated));
                 }
             }
         }
     }
     return $classMetadata;
 }
開發者ID:aliebing,項目名稱:JsonApiBundle,代碼行數:35,代碼來源:AnnotationDriver.php

示例4: loadClassMetadata

 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     $className = $reflClass->name;
     $loaded = false;
     foreach ($reflClass->getProperties() as $property) {
         if ($property->getDeclaringClass()->name == $className) {
             foreach ($this->reader->getPropertyAnnotations($property) as $groups) {
                 if ($groups instanceof Groups) {
                     foreach ($groups->getGroups() as $group) {
                         $metadata->addAttributeGroup($property->name, $group);
                     }
                 }
                 $loaded = true;
             }
         }
     }
     foreach ($reflClass->getMethods() as $method) {
         if ($method->getDeclaringClass()->name == $className) {
             foreach ($this->reader->getMethodAnnotations($method) as $groups) {
                 if ($groups instanceof Groups) {
                     if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) {
                         foreach ($groups->getGroups() as $group) {
                             $metadata->addAttributeGroup(lcfirst($matches[2]), $group);
                         }
                     } else {
                         throw new \BadMethodCallException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name));
                     }
                 }
                 $loaded = true;
             }
         }
     }
     return $loaded;
 }
開發者ID:vadim2404,項目名稱:symfony,代碼行數:38,代碼來源:AnnotationLoader.php

示例5: loadClassMetadata

 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadataInterface $classMetadata)
 {
     $reflectionClass = $classMetadata->getReflectionClass();
     $className = $reflectionClass->name;
     $loaded = false;
     $attributesMetadata = $classMetadata->getAttributesMetadata();
     foreach ($reflectionClass->getProperties() as $property) {
         if (!isset($attributesMetadata[$property->name])) {
             $attributesMetadata[$property->name] = new AttributeMetadata($property->name);
             $classMetadata->addAttributeMetadata($attributesMetadata[$property->name]);
         }
         if ($property->getDeclaringClass()->name === $className) {
             foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
                 if ($annotation instanceof Groups) {
                     foreach ($annotation->getGroups() as $group) {
                         $attributesMetadata[$property->name]->addGroup($group);
                     }
                 } elseif ($annotation instanceof MaxDepth) {
                     $attributesMetadata[$property->name]->setMaxDepth($annotation->getMaxDepth());
                 }
                 $loaded = true;
             }
         }
     }
     foreach ($reflectionClass->getMethods() as $method) {
         if ($method->getDeclaringClass()->name !== $className) {
             continue;
         }
         $accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
         if ($accessorOrMutator) {
             $attributeName = lcfirst($matches[2]);
             if (isset($attributesMetadata[$attributeName])) {
                 $attributeMetadata = $attributesMetadata[$attributeName];
             } else {
                 $attributesMetadata[$attributeName] = $attributeMetadata = new AttributeMetadata($attributeName);
                 $classMetadata->addAttributeMetadata($attributeMetadata);
             }
         }
         foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
             if ($annotation instanceof Groups) {
                 if (!$accessorOrMutator) {
                     throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
                 }
                 foreach ($annotation->getGroups() as $group) {
                     $attributeMetadata->addGroup($group);
                 }
             } elseif ($annotation instanceof MaxDepth) {
                 if (!$accessorOrMutator) {
                     throw new MappingException(sprintf('MaxDepth on "%s::%s" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
                 }
                 $attributeMetadata->setMaxDepth($annotation->getMaxDepth());
             }
             $loaded = true;
         }
     }
     return $loaded;
 }
開發者ID:Ener-Getick,項目名稱:symfony,代碼行數:60,代碼來源:AnnotationLoader.php

示例6: create

 public function create($class, \ReflectionProperty $reflectionProperty)
 {
     $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
     foreach ($annotations as $annotation) {
         if ($annotation instanceof GraphId) {
             return new IdAnnotationMetadata();
         }
     }
 }
開發者ID:graphaware,項目名稱:neo4j-php-ogm,代碼行數:9,代碼來源:IdAnnotationMetadataFactory.php

示例7: readPropertyAnnotations

 /**
  * @param \ReflectionClass $reflectionClass
  * @return Annotation[]
  * @throws AnnotationReaderException
  */
 private function readPropertyAnnotations(\ReflectionClass $reflectionClass) : array
 {
     return array_reduce($reflectionClass->getProperties(), function (array $accumulator, \ReflectionProperty $reflectionProperty) {
         /* @var $annotations \Doctrine\Common\Annotations\Annotation[] */
         $annotations = array_filter($this->reader->getPropertyAnnotations($reflectionProperty), function ($annotation) : bool {
             return $annotation instanceof Annotation;
         });
         if (empty($annotations)) {
             return $accumulator;
         }
         return array_merge($accumulator, $this->processPropertyAnnotations($annotations, $reflectionProperty));
     }, []);
 }
開發者ID:martyn82,項目名稱:apha,代碼行數:18,代碼來源:AnnotationReader.php

示例8: getPropertyMapping

 /**
  * @param \ReflectionProperty $property
  *
  * @return array
  */
 private function getPropertyMapping(ReflectionProperty $property)
 {
     $metadata = [];
     foreach ($this->reader->getPropertyAnnotations($property) as $value) {
         if (!$value instanceof RiakAnnotation) {
             continue;
         }
         $class = get_class($value);
         $name = $property->getName();
         $key = lcfirst(substr($class, strrpos($class, '\\') + 1));
         $metadata[$key] = $name;
     }
     return $metadata;
 }
開發者ID:php-riak,項目名稱:riak-client,代碼行數:19,代碼來源:DomainMetadataReader.php

示例9: readProperty

 /**
  * Reads annotations for a selected property in the class
  *
  * @param ReflectionProperty $property
  * @param ClassMetadataInterface $metadata
  */
 private function readProperty(ReflectionProperty $property, ClassMetadataInterface $metadata)
 {
     // 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);
     }
 }
開發者ID:rdohms,項目名稱:dms-filter,代碼行數:22,代碼來源:AnnotationLoader.php

示例10: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ResourceMetadata $resourceMetadata)
 {
     // get all class annotations
     $reflClass = new \ReflectionClass($className);
     $classAnnotations = $this->reader->getClassAnnotations($reflClass);
     $classAnnotations = $this->indexAnnotationsByType($classAnnotations);
     $resourceAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Resource');
     if ($resourceAnnotation !== false) {
         if (!empty($resourceAnnotation->name)) {
             $resourceMetadata->setName($resourceAnnotation->name);
         } else {
             $resourceName = Inflector::tableize(substr($className, strrpos($className, '\\') + 1));
             $resourceMetadata->setName($resourceName);
         }
     }
     $handlerAnnotation = $this->getAnnotation($classAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\Handler');
     if ($handlerAnnotation !== false) {
         if (!empty($handlerAnnotation->service)) {
             $resourceMetadata->setService($handlerAnnotation->service);
         }
     }
     // properties
     $subResources = array();
     foreach ($reflClass->getProperties() as $reflProp) {
         $propAnnotations = $this->reader->getPropertyAnnotations($reflProp);
         $propAnnotations = $this->indexAnnotationsByType($propAnnotations);
         $subResourceAnnotation = $this->getAnnotation($propAnnotations, 'BedRest\\Resource\\Mapping\\Annotation\\SubResource');
         if ($subResourceAnnotation !== false) {
             $subResources[$subResourceAnnotation->name] = array('fieldName' => $reflProp->name, 'service' => $subResourceAnnotation->service);
         }
     }
     $resourceMetadata->setSubResources($subResources);
 }
開發者ID:bedrest,項目名稱:bedrest,代碼行數:36,代碼來源:AnnotationDriver.php

示例11: getConverterAnnotation

 /**
  * Get converter annotation
  *
  * @param \ReflectionProperty $property
  *
  * @return Money
  *
  * @throws MoneyAnnotationNotFoundException
  */
 private function getConverterAnnotation(\ReflectionProperty $property)
 {
     $annotations = $this->reader->getPropertyAnnotations($property);
     $moneyAnnotation = null;
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Money) {
             if ($moneyAnnotation) {
                 throw new \RuntimeException(sprintf('Many Money annotation in property %s->%s', $property->getDeclaringClass()->getName(), $property->getName()));
             }
             $moneyAnnotation = $annotation;
         }
     }
     if ($moneyAnnotation) {
         return $moneyAnnotation;
     }
     throw new MoneyAnnotationNotFoundException(sprintf('Not found DateTime annotation in property %s->%s', $property->getDeclaringClass()->getName(), $property->getName()));
 }
開發者ID:Gtvar,項目名稱:FivePercent-Converter,代碼行數:26,代碼來源:MoneyPropertyConverterAnnotationReader.php

示例12: getPropertyAnnotations

 /**
  * Get annotations for property
  *
  * @param \ReflectionProperty $property
  * @return array
  */
 public function getPropertyAnnotations(\ReflectionProperty $property)
 {
     $annotations = array();
     foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
         $annotations[get_class($annot)] = $annot;
     }
     return $annotations;
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:14,代碼來源:IndexedReader.php

示例13: loadClassMetadata

 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     $className = $reflClass->name;
     $success = false;
     foreach ($this->reader->getClassAnnotations($reflClass) as $constraint) {
         if ($constraint instanceof GroupSequence) {
             $metadata->setGroupSequence($constraint->groups);
         } elseif ($constraint instanceof GroupSequenceProvider) {
             $metadata->setGroupSequenceProvider(true);
         } elseif ($constraint instanceof Constraint) {
             $metadata->addConstraint($constraint);
         }
         $success = true;
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($property->getDeclaringClass()->name == $className) {
             foreach ($this->reader->getPropertyAnnotations($property) as $constraint) {
                 if ($constraint instanceof Constraint) {
                     $metadata->addPropertyConstraint($property->name, $constraint);
                 }
                 $success = true;
             }
         }
     }
     foreach ($reflClass->getMethods() as $method) {
         if ($method->getDeclaringClass()->name == $className) {
             foreach ($this->reader->getMethodAnnotations($method) as $constraint) {
                 if ($constraint instanceof Callback) {
                     $constraint->callback = $method->getName();
                     $constraint->methods = null;
                     $metadata->addConstraint($constraint);
                 } elseif ($constraint instanceof Constraint) {
                     if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) {
                         $metadata->addGetterConstraint(lcfirst($matches[2]), $constraint);
                     } else {
                         throw new MappingException(sprintf('The constraint on "%s::%s" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name));
                     }
                 }
                 $success = true;
             }
         }
     }
     return $success;
 }
開發者ID:tahermarkos,項目名稱:Transport,代碼行數:48,代碼來源:AnnotationLoader.php

示例14: parseSingleClassFile

 private function parseSingleClassFile($className)
 {
     //annotation on class
     $reflectionClass = new \ReflectionClass($className);
     $classAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass);
     if (!$classAnnotations) {
         return;
     }
     foreach ($classAnnotations as $classAnnotation) {
         //name not set => bean name className?
         if (!isset($classAnnotation->name) or $classAnnotation->name == '') {
             $beanClassName = lcfirst(join('', array_slice(explode('\\', $className), -1)));
             $classAnnotation->name = $beanClassName;
         }
         $bean = array('name' => $classAnnotation->name, 'class' => $className, 'scope' => $classAnnotation->scope, 'lazyInit' => (string) $classAnnotation->lazyInit);
         //annotation on method
         $methods = $reflectionClass->getMethods();
         foreach ($methods as $method) {
             if ($method->name == self::CONSTRUCT_METHOD) {
                 //annotaiton on construct
                 $bean = $this->analyzeConstruct($className, $method, $bean);
             } else {
                 $reflectionMethod = new \ReflectionMethod($className, $method->name);
                 $methodAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod);
                 if ($methodAnnotations) {
                     foreach ($methodAnnotations as $pathToClassFile) {
                         if (isset($method->name)) {
                             $bean[get_class($pathToClassFile)] = $method->name;
                         }
                     }
                 }
             }
         }
         //annotation on properties
         $properties = $reflectionClass->getProperties();
         $allProperties = array();
         $temp = array();
         foreach ($properties as $property) {
             $reflectionProperty = new \ReflectionProperty($className, $property->name);
             $propertyAnnotations = $this->annotationReader->getPropertyAnnotations($reflectionProperty);
             if ($propertyAnnotations) {
                 foreach ($propertyAnnotations as $pathToClassFile) {
                     $allProperties[$property->name] = array(get_class($pathToClassFile) => $pathToClassFile->name);
                     if ($pathToClassFile->ref) {
                         $temp[] = array('name' => $property->name, 'ref' => $pathToClassFile->ref);
                     } else {
                         $temp[] = array('name' => $property->name, 'value' => $this->replaceVariable($pathToClassFile->value), 'type' => $pathToClassFile->type);
                     }
                 }
             }
             if ($temp) {
                 $bean['properties'] = $temp;
             }
         }
         $this->context[$classAnnotation->name] = $bean;
     }
 }
開發者ID:db80,項目名稱:ovo-container,代碼行數:57,代碼來源:AnnotationContextReader.php

示例15: getClassMetadata

 /**
  * Return the class metadata instance
  * 
  * @param string $entityName
  * 
  * @return ClassMetaDataCollection
  */
 public function getClassMetadata($entityName)
 {
     $r = new ReflectionClass($entityName);
     $instanceMetadataCollection = new ClassMetaDataCollection();
     $instanceMetadataCollection->name = $entityName;
     $classAnnotations = $this->reader->getClassAnnotations($r);
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof RepositoryAttribute) {
             $instanceMetadataCollection->setRepository($classAnnotation->getValue());
         }
         if ($classAnnotation instanceof ObjectClass) {
             $instanceMetadataCollection->setObjectClass($classAnnotation->getValue());
         }
         if ($classAnnotation instanceof SearchDn) {
             $instanceMetadataCollection->setSearchDn($classAnnotation->getValue());
         }
         if ($classAnnotation instanceof Dn) {
             $instanceMetadataCollection->setDn($classAnnotation->getValue());
         }
     }
     foreach ($r->getProperties() as $publicAttr) {
         $annotations = $this->reader->getPropertyAnnotations($publicAttr);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Attribute) {
                 $varname = $publicAttr->getName();
                 $attribute = $annotation->getName();
                 $instanceMetadataCollection->addMeta($varname, $attribute);
             }
             if ($annotation instanceof DnLinkArray) {
                 $varname = $publicAttr->getName();
                 $instanceMetadataCollection->addArrayOfLink($varname, $annotation->getValue());
             }
             if ($annotation instanceof Sequence) {
                 $varname = $publicAttr->getName();
                 $instanceMetadataCollection->addSequence($varname, $annotation->getValue());
             }
             if ($annotation instanceof DnPregMatch) {
                 $varname = $publicAttr->getName();
                 $instanceMetadataCollection->addRegex($varname, $annotation->getValue());
             }
             if ($annotation instanceof ParentDn) {
                 $varname = $publicAttr->getName();
                 $instanceMetadataCollection->addParentLink($varname, $annotation->getValue());
             }
             if ($annotation instanceof ArrayField) {
                 $instanceMetadataCollection->addArrayField($varname);
             }
             if ($annotation instanceof Must) {
                 $instanceMetadataCollection->addMust($varname);
             }
             if ($annotation instanceof Operational) {
                 $instanceMetadataCollection->addOperational($varname);
             }
         }
     }
     return $instanceMetadataCollection;
 }
開發者ID:t73biz,項目名稱:ldap-orm-bundle,代碼行數:64,代碼來源:LdapEntityManager.php


注:本文中的Doctrine\Common\Annotations\Reader::getPropertyAnnotations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。