当前位置: 首页>>代码示例>>PHP>>正文


PHP Reader::getPropertyAnnotation方法代码示例

本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getPropertyAnnotation方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getPropertyAnnotation方法的具体用法?PHP Reader::getPropertyAnnotation怎么用?PHP Reader::getPropertyAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Annotations\Reader的用法示例。


在下文中一共展示了Reader::getPropertyAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: convert

 /**
  * @param array $request
  * @param \ReflectionClass $class
  * @param callable $nameMangling
  *
  * @return ConversionResult
  */
 public function convert(array $request, \ReflectionClass $class, callable $nameMangling)
 {
     $ctx = new Context($this, $this->coercer, $nameMangling);
     $object = $this->instance($class);
     $setter = $this->setter($object);
     $errors = [];
     foreach ($class->getProperties() as $prop) {
         $name = $nameMangling($prop->getName());
         if (!isset($request[$name]) && !$this->reader->getPropertyAnnotation($prop, Optional::class)) {
             $errors[] = new MissingFieldError($name);
             continue;
         } elseif (!\array_key_exists($name, $request)) {
             continue;
         }
         $value = $request[$name];
         $typeAnnotation = $this->reader->getPropertyAnnotation($prop, Type::class);
         if ($value !== null && $typeAnnotation instanceof Type) {
             try {
                 $result = $this->coercer->coerce($value, $typeAnnotation->type, $ctx);
             } catch (CoercionException $e) {
                 throw ConverterException::in($class->getName(), $prop->getName(), $e);
             }
             $value = $result->getValue();
             $errors = \array_merge($errors, $result->errorsInField($name));
             $setter->set($prop->getName(), $value);
         } elseif ($value === null) {
             $setter->set($prop->getName(), null);
         }
     }
     return ConversionResult::errors($errors, $object);
 }
开发者ID:nikita2206,项目名称:symfony-request-converter,代码行数:38,代码来源:Converter.php

示例2: loadMetadataForClass

 /**
  * @param \ReflectionClass $class
  *
  * @return \Metadata\ClassMetadata
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $metadata = new ClassMetadata($class->getName());
     // Resource annotation
     $annotation = $this->reader->getClassAnnotation($class, 'Conjecto\\Nemrod\\ResourceManager\\Annotation\\Resource');
     if (null !== $annotation) {
         $types = $annotation->types;
         $pattern = $annotation->uriPattern;
         if (!is_array($types)) {
             $types = array($types);
         }
         $metadata->types = $types;
         $metadata->uriPattern = $pattern;
     }
     foreach ($class->getProperties() as $reflectionProperty) {
         $propMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());
         // Property annotation
         $annotation = $this->reader->getPropertyAnnotation($reflectionProperty, 'Conjecto\\Nemrod\\ResourceManager\\Annotation\\Property');
         if (null !== $annotation) {
             $propMetadata->value = $annotation->value;
             $propMetadata->cascade = $annotation->cascade;
         }
         $metadata->addPropertyMetadata($propMetadata);
     }
     return $metadata;
 }
开发者ID:conjecto,项目名称:nemrod,代码行数:31,代码来源:AnnotationDriver.php

示例3: loadMetadataForClass

 /**
  * @param \ReflectionClass $class
  *
  * @return \Metadata\ClassMetadata
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $metadata = $this->driver->loadMetadataForClass($class);
     foreach ($metadata->propertyMetadata as $key => $propertyMetadata) {
         $type = $propertyMetadata->type['name'];
         if (!$propertyMetadata->reflection) {
             continue;
         }
         /** @var PropertyMetadata $propertyMetadata */
         /** @var HandledType $annot */
         $annot = $this->reader->getPropertyAnnotation($propertyMetadata->reflection, HandledType::class);
         if (!$annot) {
             continue;
         }
         $isCollection = false;
         $collectionType = null;
         if (in_array($type, ['array', 'ArrayCollection'], true)) {
             $isCollection = true;
             $collectionType = $type;
             $type = $propertyMetadata->type['params'][0]['name'];
         }
         $handler = $annot->handler ?: 'Relation';
         $newType = sprintf('%s<%s>', $handler, $type);
         if ($isCollection) {
             $newType = sprintf('%s<%s<%s>>', $collectionType, $handler, $type);
         }
         $propertyMetadata->setType($newType);
     }
     return $metadata;
 }
开发者ID:bankiru,项目名称:jsonrpc-server-bundle,代码行数:35,代码来源:HandledTypeDriver.php

示例4: fillFromArray

 /**
  * @param $object
  * @param $classRefl
  * @param $segmentData
  * @throws MandatorySegmentPieceMissing
  */
 protected function fillFromArray($object, $classRefl, $segmentData)
 {
     foreach ($classRefl->getProperties() as $propRefl) {
         $isSegmentPiece = $this->annotationReader->getPropertyAnnotation($propRefl, SegmentPiece::class);
         if ($isSegmentPiece) {
             $piece = isset($segmentData[$isSegmentPiece->position]) ? $segmentData[$isSegmentPiece->position] : null;
             $propRefl->setAccessible(true);
             if ($isSegmentPiece->parts) {
                 $value = array();
                 $i = 0;
                 foreach ($isSegmentPiece->parts as $k => $part) {
                     if (!is_numeric($k) && is_array($part)) {
                         $partName = $k;
                         if (!empty($piece) && in_array("@mandatory", $part) && $this->isEmpty($piece[$i])) {
                             throw new MandatorySegmentPieceMissing(sprintf("Segment %s part %s missing value at offset %d", $segmentData[0], $partName, $i));
                         }
                     } else {
                         $partName = $part;
                     }
                     $value[$partName] = isset($piece[$i]) ? $piece[$i] : null;
                     ++$i;
                 }
                 $propRefl->setValue($object, $value);
             } else {
                 $propRefl->setValue($object, $piece);
             }
         }
     }
 }
开发者ID:progrupa,项目名称:edifact,代码行数:35,代码来源:Populator.php

示例5: getForm

 public function getForm(ResourceInterface $resource)
 {
     $resourceClassName = \Doctrine\Common\Util\ClassUtils::getClass($resource);
     $resourceParts = explode("\\", $resourceClassName);
     $resourceParts[count($resourceParts) - 2] = 'Form';
     $resourceParts[count($resourceParts) - 1] .= 'Type';
     $formType = implode("\\", $resourceParts);
     if (class_exists($formType)) {
         return $this->formFactory->create(new $formType(), $resource);
     }
     $options = array('data_class' => $resourceClassName);
     $builder = $this->formFactory->createBuilder('form', $resource, $options);
     $reflectionClass = new \ReflectionClass($resourceClassName);
     $annotationClass = 'uebb\\HateoasBundle\\Annotation\\FormField';
     foreach ($reflectionClass->getProperties() as $propertyReflection) {
         /**
          * @var \uebb\HateoasBundle\Annotation\FormField $annotation
          */
         $annotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClass);
         if ($annotation) {
             $builder->add($propertyReflection->getName(), $annotation->type, is_array($annotation->options) ? $annotation->options : array());
         }
     }
     $form = $builder->getForm();
     return $form;
 }
开发者ID:uebb,项目名称:hateoas-bundle,代码行数:26,代码来源:FormResolver.php

示例6: getProperties

 /**
  * @param ReflectionClass $class
  *
  * @return array
  */
 public function getProperties(ReflectionClass $class)
 {
     $properties = $class->getProperties();
     $propertyAnnotations = [];
     foreach ($properties as $property) {
         $annotationName = $this->reader->getPropertyAnnotation($property, Field::class);
         if ($annotationName) {
             $annotationName = $annotationName->getName();
             $propertyAnnotations[$property->getName()] = $annotationName;
         }
     }
     return array_flip($propertyAnnotations);
 }
开发者ID:refinery29,项目名称:solr-annotations,代码行数:18,代码来源:Parser.php

示例7: addNestedEmbeddedClasses

 /**
  * @param EmbeddedMetadataInterface $embeddedMetadata
  *
  * @return EmbeddedMetadataInterface
  */
 private function addNestedEmbeddedClasses(EmbeddedMetadataInterface $embeddedMetadata)
 {
     $reflClass = new \ReflectionClass($embeddedMetadata->getClassAttribute());
     foreach ($reflClass->getProperties() as $reflProperty) {
         if ($annotation = $this->reader->getPropertyAnnotation($reflProperty, Index::class)) {
             $embeddedMetadata->addEmbeddableClass(new IndexMetadata($reflProperty->class, $reflProperty->name, $annotation->name, $annotation->type));
         }
         if ($annotation = $this->reader->getPropertyAnnotation($reflProperty, Embedded::class)) {
             $nested = $this->addNestedEmbeddedClasses(new EmbeddedMetadata($reflProperty->class, $reflProperty->name, $annotation->class));
             $embeddedMetadata->addEmbeddableClass($nested);
         }
     }
     return $embeddedMetadata;
 }
开发者ID:sergiors,项目名称:taxonomy,代码行数:19,代码来源:AnnotationDriver.php

示例8: readUploadableField

 /**
  * Attempts to read the uploadable field annotation of the
  * specified property.
  *
  * @param \ReflectionClass $class The class.
  * @param string $field The field
  * @return null|\Vich\UploaderBundle\Annotation\UploadableField The uploadable field.
  */
 public function readUploadableField(\ReflectionClass $class, $field)
 {
     try {
         $prop = $class->getProperty($field);
         $field = $this->reader->getPropertyAnnotation($prop, 'Vich\\UploaderBundle\\Mapping\\Annotation\\UploadableField');
         if (null === $field) {
             return null;
         }
         $field->setPropertyName($prop->getName());
         return $field;
     } catch (\ReflectionException $e) {
         return null;
     }
 }
开发者ID:neoshadybeat,项目名称:VichUploaderBundle,代码行数:22,代码来源:AnnotationDriver.php

示例9: getTypeFromProperty

 /**
  * Get the designated class name from the given property
  * 
  * @param mixed $property Can be either a \ReflectionProperty or a primitive string type.
  * @return string If $property was a primitive string type (ie <array>) then that string is returned.
  *					If $property is a \ReflectionProperty, the type of that property is returned, or null if
  *					one could not be determined.
  */
 public function getTypeFromProperty($property)
 {
     if (is_string($property)) {
         throw new \InvalidArgumentException('Parameter $property cannot be a string unless the string is a valid primitive type');
     }
     $typeAnnotation = $this->annotationReader->getPropertyAnnotation($property, 'Rezonant\\MapperBundle\\Annotations\\Type');
     if ($typeAnnotation) {
         return $typeAnnotation->value;
     }
     $typeAnnotation = $this->annotationReader->getPropertyAnnotation($property, 'JMS\\Serializer\\Annotation\\Type');
     if ($typeAnnotation) {
         return $typeAnnotation->name;
     }
     return null;
 }
开发者ID:Luwdo,项目名称:RezonantMapperBundle,代码行数:23,代码来源:Reflector.php

示例10: convert

 /**
  * Form annotation converter.
  *
  * @param object $form
  *
  * @return array
  */
 public function convert($form)
 {
     $data = array();
     $reflection = new \ReflectionObject($form);
     foreach ($reflection->getProperties() as $property) {
         $annotation = $this->_reader->getPropertyAnnotation($property, $this->_annotation);
         if ($annotation !== null) {
             if (method_exists($annotation, 'setName')) {
                 $annotation->setName($property->getName());
             }
             $data[] = $annotation;
         }
     }
     return $data;
 }
开发者ID:jeboehm,项目名称:lampcp,代码行数:22,代码来源:AnnotationConverter.php

示例11: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $classMetadata = new MergeableClassMetadata($class->getName());
     foreach ($class->getProperties() as $reflectionProperty) {
         $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());
         /** @var \Integrated\Bundle\SlugBundle\Mapping\Annotations\Slug $annotation */
         $annotation = $this->reader->getPropertyAnnotation($reflectionProperty, 'Integrated\\Bundle\\SlugBundle\\Mapping\\Annotations\\Slug');
         if (null !== $annotation) {
             $propertyMetadata->slugFields = $annotation->fields;
             $propertyMetadata->slugSeparator = $annotation->separator;
         }
         $classMetadata->addPropertyMetadata($propertyMetadata);
     }
     return $classMetadata;
 }
开发者ID:integratedfordevelopers,项目名称:integrated-slug-bundle,代码行数:18,代码来源:AnnotationDriver.php

示例12: loadClassMetadata

 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadataInterface $classMetadata, array $normalizationGroups = null, array $denormalizationGroups = null, array $validationGroups = null)
 {
     $reflectionClass = $classMetadata->getReflectionClass();
     if ($iri = $this->reader->getClassAnnotation($reflectionClass, self::IRI_ANNOTATION_NAME)) {
         $classMetadata = $classMetadata->withIri($iri->value);
     }
     foreach ($classMetadata->getAttributesMetadata() as $attributeName => $attributeMetadata) {
         if ($reflectionProperty = $this->getReflectionProperty($reflectionClass, $attributeName)) {
             if ($iri = $this->reader->getPropertyAnnotation($reflectionProperty, self::IRI_ANNOTATION_NAME)) {
                 $classMetadata = $classMetadata->withAttributeMetadata($attributeName, $attributeMetadata->withIri($iri->value));
             }
         }
     }
     return $classMetadata;
 }
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:18,代码来源:AnnotationLoader.php

示例13: getFieldsConfiguration

 /**
  * Creates form configuration for $model for given $fields
  *
  * @param object $model
  * @param array $fields
  * @return array
  */
 private function getFieldsConfiguration($model, $fields = array())
 {
     $configuration = $properties = array();
     $ro = new \ReflectionObject($model);
     if (empty($fields)) {
         $properties = $ro->getProperties();
     } else {
         foreach (array_keys($fields) as $field) {
             $properties[] = $ro->getProperty($field);
         }
     }
     foreach ($properties as $property) {
         $propertyIsListed = array_key_exists($property->getName(), $fields);
         if (!empty($fields) && !$propertyIsListed) {
             continue;
         }
         $fieldConfiguration = $this->annotationReader->getPropertyAnnotation($property, 'Codete\\FormGeneratorBundle\\Annotations\\Display');
         if ($fieldConfiguration === null && !$propertyIsListed) {
             continue;
         }
         $configuration[$property->getName()] = (array) $fieldConfiguration;
         if (isset($fields[$property->getName()])) {
             $configuration[$property->getName()] = array_replace_recursive($configuration[$property->getName()], $fields[$property->getName()]);
         }
         // this variable comes from Doctrine\Common\Annotations\Annotation
         unset($configuration[$property->getName()]['value']);
     }
     return $configuration;
 }
开发者ID:KrzysztofMoskalik,项目名称:FormGeneratorBundle,代码行数:36,代码来源:FormGenerator.php

示例14: getCollectionsItemNames

 /**
  * Get a list linking an item name with the property it refers to and what kind of collection it is.
  * Ex: [
  *   "byItemName" => "user" => ["property" => "users", "behavior" => "list", "methods" => ["add", "remove"]],
  *   "byProperty" => "users" => ["itemName" => "user", "behavior" => "list", "methods" => ["add", "remove"]]
  * ]
  *
  * @param array  $properties The properties of the object to read.
  * @param \Doctrine\Common\Annotations\Reader $annotationReader The annotation reader to use.
  *
  * @return array The described list.
  */
 public static function getCollectionsItemNames($properties, $annotationReader)
 {
     $objectCollectionsItemNames = array("byProperty" => array(), "byItemName" => array());
     foreach ($properties as $propertyName => $property) {
         $annotation = null;
         $behavior = null;
         foreach (self::$collectionAnnotationClasses as $annotationBehavior => $annotationClass) {
             $annotation = $annotationReader->getPropertyAnnotation($property, $annotationClass);
             if ($annotation !== null) {
                 $behavior = $annotationBehavior;
                 break;
             }
         }
         if ($annotation !== null) {
             // get the item name, or deduce it (singularize the property name)
             $itemName = $annotation->getItemName();
             if ($itemName === null) {
                 $itemName = Inflector::singularize($propertyName);
             }
             $objectCollectionsItemNames["byItemName"][$itemName] = array("property" => $propertyName, "behavior" => $behavior, "methods" => $annotation->getMethods());
             $objectCollectionsItemNames["byProperty"][$propertyName] = array("itemName" => $itemName, "behavior" => $behavior, "methods" => $annotation->getMethods());
         }
     }
     return $objectCollectionsItemNames;
 }
开发者ID:antarestupin,项目名称:Accessible,代码行数:37,代码来源:CollectionsReader.php

示例15: getPropertiesByType

 /**
  * reads the entity and returns a set of annotations
  *
  * @param string $entity
  * @param string $type
  *
  * @return Annotation[]
  */
 private function getPropertiesByType($entity, $type)
 {
     $properties = $this->readClassProperties($entity);
     $fields = array();
     foreach ($properties as $property) {
         $annotation = $this->reader->getPropertyAnnotation($property, $type);
         if (null === $annotation) {
             continue;
         }
         $property->setAccessible(true);
         $annotation->value = $property->getValue($entity);
         $annotation->name = $property->getName();
         $fields[] = $annotation;
     }
     return $fields;
 }
开发者ID:zquintana,项目名称:SolrBundle,代码行数:24,代码来源:AnnotationReader.php


注:本文中的Doctrine\Common\Annotations\Reader::getPropertyAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。