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


PHP AnnotationReader::getPropertyAnnotations方法代码示例

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


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

示例1: loadPropertyMetadata

 /**
  * @param ReflectionProperty $property
  * @return PropertyMetadata
  */
 private function loadPropertyMetadata(ReflectionProperty $property)
 {
     $propertyMetadata = new PropertyMetadata($property->getDeclaringClass()->getName(), $property->getName());
     foreach ($this->reader->getPropertyAnnotations($property) as $propertyAnnotation) {
         if ($propertyAnnotation instanceof Type) {
             $propertyMetadata->type = $propertyAnnotation->name;
         }
         if ($propertyAnnotation instanceof ReferenceOne) {
             $propertyMetadata->reference = PropertyMetadata::REFERENCE_ONE;
             $propertyMetadata->target = $propertyAnnotation->target;
         }
         if ($propertyAnnotation instanceof ReferenceMany) {
             $propertyMetadata->reference = PropertyMetadata::REFERENCE_MANY;
             $propertyMetadata->target = $propertyAnnotation->target;
         }
         if ($propertyAnnotation instanceof ReferenceKey) {
             $propertyMetadata->reference = PropertyMetadata::REFERENCE_KEY;
             $propertyMetadata->target = $propertyAnnotation->target;
             if ($propertyAnnotation->value instanceof Type) {
                 $propertyMetadata->value = ['type' => 'type', 'name' => $propertyAnnotation->value->name];
             }
         }
         if ($propertyAnnotation instanceof EmbedOne) {
             $propertyMetadata->embed = PropertyMetadata::EMBED_ONE;
             $propertyMetadata->target = $propertyAnnotation->target;
             $propertyMetadata->mapping = $propertyAnnotation->mapping;
         }
         if ($propertyAnnotation instanceof EmbedMany) {
             $propertyMetadata->embed = PropertyMetadata::EMBED_MANY;
             $propertyMetadata->target = $propertyAnnotation->target;
             $propertyMetadata->mapping = $propertyAnnotation->mapping;
         }
     }
     return $propertyMetadata;
 }
开发者ID:davidbadura,项目名称:orangedb,代码行数:39,代码来源:AnnotationDriver.php

示例2: getFieldsMetadata

 /**
  * @param string $classname
  * @return array
  */
 public function getFieldsMetadata($classname)
 {
     foreach ($this->getReflectionClass($classname)->getProperties() as $property) {
         $properties = array_reduce($this->reader->getPropertyAnnotations($property), function ($reduced, $current) use($property, $classname) {
             if ($current instanceof AbstractField) {
                 $current->name = $property->getName();
                 if (is_object($classname)) {
                     $property->setAccessible(true);
                     $current->value = $property->getValue($classname);
                 }
                 $key = get_class($current);
                 if (isset($reduced[$key])) {
                     if (!is_array($reduced[$key])) {
                         $reduced[$key] = [$reduced[$key]];
                     }
                     $reduced[$key][] = $current;
                 } else {
                     $reduced[$key] = $current;
                 }
                 return $reduced;
             }
         });
         if (!is_null($properties)) {
             $fields[$property->getName()] = $properties;
         }
     }
     return $fields;
 }
开发者ID:eoko,项目名称:odm-metadata-annotation,代码行数:32,代码来源:AnnotationDriver.php

示例3: loadMetadataForClass

 public function loadMetadataForClass($className)
 {
     $metadata = new ClassMetadata($className);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionProperties = $reflectionClass->getProperties();
     foreach ($reflectionProperties as $reflectionProperty) {
         $name = $reflectionProperty->getName();
         $pMetadata = new PropertyMetadata($name);
         $annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Annotations\Expose) {
                 $pMetadata->setExpose((bool) $annotation->value);
             } elseif ($annotation instanceof Annotations\Type) {
                 $pMetadata->setType((string) $annotation->value);
             } elseif ($annotation instanceof Annotations\Groups) {
                 $pMetadata->setGroups($annotation->value);
             } elseif ($annotation instanceof Annotations\SerializedName) {
                 $pMetadata->setSerializedName((string) $annotation->value);
             } elseif ($annotation instanceof Annotations\SinceVersion) {
                 $pMetadata->setSinceVersion((string) $annotation->value);
             } elseif ($annotation instanceof Annotations\UntilVersion) {
                 $pMetadata->setUntilVersion((string) $annotation->value);
             }
         }
         $metadata->addPropertyMetadata($pMetadata);
     }
     return $metadata;
 }
开发者ID:sugatov,项目名称:simple-serializer,代码行数:28,代码来源:AnnotationDriver.php

示例4: getPropertyAnnotationClassNames

 public function getPropertyAnnotationClassNames($className, $propertyName = NULL)
 {
     $reflectionProperty = new \ReflectionProperty($className, $propertyName);
     $annotations = $this->annotationReader->getPropertyAnnotations($reflectionProperty);
     $classNames = array();
     foreach ($annotations as $annotation) {
         $classNames[] = get_class($annotation);
     }
     return array_unique($classNames);
 }
开发者ID:mia3,项目名称:expose,代码行数:10,代码来源:ReflectionService.php

示例5: getPropertyAnnotations

 /**
  * @param array $properties
  * @param object $class
  * @return array
  */
 public function getPropertyAnnotations(array $properties, $class)
 {
     $contraints = array();
     // Foreach the sync and retrieve the anotation
     foreach ($properties as $property) {
         $propertyReflection = new \ReflectionProperty($class, $property);
         $annotation = $this->annotationReader->getPropertyAnnotations($propertyReflection);
         if (empty($annotation) === false) {
             $contraints[$property] = $annotation;
         }
     }
     return $contraints;
 }
开发者ID:fezfez,项目名称:keep-update,代码行数:18,代码来源:AnnotationDAO.php

示例6: parse

 /**
  * {@inheritdoc}
  */
 public function parse(TransportableInterface $transport)
 {
     $resource = new ResourceMapping();
     //  Gain a reflection instance of the given class and retrieve all the properties marked as protected.
     $class = new ReflectionObject($transport);
     $properties = $class->getProperties(ReflectionProperty::IS_PROTECTED);
     foreach ($properties as $property) {
         $annotations = new ArrayCollection($this->reader->getPropertyAnnotations($property));
         $this->processFieldAnnotationsForResourceMapping($resource, $property, $annotations);
     }
     $this->validateResourceMapping($resource);
     return $resource;
 }
开发者ID:umber-io,项目名称:rei,代码行数:16,代码来源:AnnotationParser.php

示例7: fillEntity

 /**
  * {@inheritdoc}
  */
 public function fillEntity(Utils\ArrayHash $values, Entities\IEntity $entity, $isNew = FALSE)
 {
     $classMetadata = $this->managerRegistry->getManagerForClass(get_class($entity))->getClassMetadata(get_class($entity));
     foreach (array_merge($classMetadata->getFieldNames(), $classMetadata->getAssociationNames()) as $fieldName) {
         $propertyReflection = new Nette\Reflection\Property(get_class($entity), $fieldName);
         /** @var Doctrine\Mapping\Annotation\Crud $crud */
         if ($crud = $this->annotationReader->getPropertyAnnotation($propertyReflection, self::EXTENSION_ANNOTATION)) {
             if ($isNew && $crud->isRequired() && !$values->offsetExists($fieldName)) {
                 throw new Exceptions\InvalidStateException('Missing required key "' . $fieldName . '"');
             }
             if (!$values->offsetExists($fieldName) || !$isNew && !$crud->isWritable() || $isNew && !$crud->isRequired()) {
                 continue;
             }
             $value = $values->offsetGet($fieldName);
             if ($value instanceof Utils\ArrayHash || is_array($value)) {
                 if (!$classMetadata->getFieldValue($entity, $fieldName) instanceof Entities\IEntity) {
                     $propertyAnnotations = $this->annotationReader->getPropertyAnnotations($propertyReflection);
                     $annotations = array_map(function ($annotation) {
                         return get_class($annotation);
                     }, $propertyAnnotations);
                     if (in_array('Doctrine\\ORM\\Mapping\\OneToOne', $annotations, TRUE)) {
                         $className = $this->annotationReader->getPropertyAnnotation($propertyReflection, 'Doctrine\\ORM\\Mapping\\OneToOne')->targetEntity;
                     } elseif (in_array('Doctrine\\ORM\\Mapping\\ManyToOne', $annotations, TRUE)) {
                         $className = $this->annotationReader->getPropertyAnnotation($propertyReflection, 'Doctrine\\ORM\\Mapping\\ManyToOne')->targetEntity;
                     } else {
                         $className = $propertyReflection->getAnnotation('var');
                     }
                     // Check if class is callable
                     if (class_exists($className)) {
                         $classMetadata->setFieldValue($entity, $fieldName, new $className());
                     } else {
                         $classMetadata->setFieldValue($entity, $fieldName, $value);
                     }
                 }
                 // Check again if entity was created
                 if (($fieldValue = $classMetadata->getFieldValue($entity, $fieldName)) && $fieldValue instanceof Entities\IEntity) {
                     $classMetadata->setFieldValue($entity, $fieldName, $this->fillEntity(Utils\ArrayHash::from((array) $value), $fieldValue, $isNew));
                 }
             } else {
                 if ($crud->validator !== NULL) {
                     $value = $this->validateProperty($crud->validator, $value);
                 }
                 $classMetadata->setFieldValue($entity, $fieldName, $value);
             }
         }
     }
     return $entity;
 }
开发者ID:iPublikuj,项目名称:doctrine,代码行数:51,代码来源:EntityMapper.php

示例8: getContentFiles

 public function getContentFiles($object)
 {
     $reflectedClass = new \ReflectionClass($object);
     $reader = new AnnotationReader();
     $annotations = $reader->getClassAnnotations($reflectedClass);
     $isContentFiledClass = false;
     foreach ($annotations as $annotation) {
         if ($annotation instanceof ContentFiled) {
             $isContentFiledClass = true;
         }
     }
     if (!$isContentFiledClass) {
         throw new \InvalidArgumentException('Only @ContentFiled annotated classes are supported!');
     }
     $contentFiles = [];
     foreach ($reflectedClass->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof ContentFileAnnotation) {
                 $mappingType = $object->{$annotation->mappingTypeMethod}();
                 $contentFiles = array_merge($contentFiles, $this->contentFileManager->findFilesByMappingType($mappingType));
             }
         }
     }
     return $contentFiles;
 }
开发者ID:scigroup,项目名称:tinyuplmngr,代码行数:25,代码来源:ContentFiledManager.php

示例9: create

 /**
  * @param string $className
  * @return Datagrid
  */
 public function create($className)
 {
     /** @var \Doctrine\ORM\EntityManager $entityManager */
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $metadata = $entityManager->getClassMetadata($className);
     $reflection = $metadata->getReflectionClass();
     $datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array()));
     $reader = new AnnotationReader();
     foreach ($reader->getClassAnnotations($reflection) as $annotation) {
         $params = compact('datagridSpec', 'annotation');
         $this->getEventManager()->trigger('discoverTitle', $this, $params);
     }
     foreach ($reflection->getProperties() as $property) {
         foreach ($reader->getPropertyAnnotations($property) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'property');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     foreach ($reflection->getMethods() as $method) {
         foreach ($reader->getMethodAnnotations($method) as $annotation) {
             $params = compact('datagridSpec', 'annotation', 'method');
             $this->getEventManager()->trigger('configureColumn', $this, $params);
         }
     }
     $this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy());
     return $this->datagrids[$className];
 }
开发者ID:PoetikDragon,项目名称:USCSS,代码行数:31,代码来源:DatagridManager.php

示例10: loadClassValue

 /**
  * Load all of the @XmlValue annotations
  * 
  * @param ClassMetadata $metadata
  */
 protected function loadClassValue(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     foreach ($reflClass->getProperties() as $property) {
         foreach ($this->reader->getPropertyAnnotations($property) as $annotation) {
             if ($annotation instanceof XmlValue) {
                 $metadata->setValue($property->getName());
             }
         }
     }
 }
开发者ID:kustov-vitalik,项目名称:xml-hitch,代码行数:16,代码来源:AnnotationLoader.php

示例11: testAnnotations

 public function testAnnotations()
 {
     $reader = new AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
     $reader->setDefaultAnnotationNamespace('Doctrine\\Tests\\Common\\Annotations\\');
     $class = new \ReflectionClass('Doctrine\\Tests\\Common\\Annotations\\DummyClass');
     $classAnnots = $reader->getClassAnnotations($class);
     $annotName = 'Doctrine\\Tests\\Common\\Annotations\\DummyAnnotation';
     $this->assertEquals(1, count($classAnnots));
     $this->assertTrue($classAnnots[$annotName] instanceof DummyAnnotation);
     $this->assertEquals("hello", $classAnnots[$annotName]->dummyValue);
     $field1Prop = $class->getProperty('field1');
     $propAnnots = $reader->getPropertyAnnotations($field1Prop);
     $this->assertEquals(1, count($propAnnots));
     $this->assertTrue($propAnnots[$annotName] instanceof DummyAnnotation);
     $this->assertEquals("fieldHello", $propAnnots[$annotName]->dummyValue);
     $getField1Method = $class->getMethod('getField1');
     $methodAnnots = $reader->getMethodAnnotations($getField1Method);
     $this->assertEquals(1, count($methodAnnots));
     $this->assertTrue($methodAnnots[$annotName] instanceof DummyAnnotation);
     $this->assertEquals(array(1, 2, "three"), $methodAnnots[$annotName]->value);
     $field2Prop = $class->getProperty('field2');
     $propAnnots = $reader->getPropertyAnnotations($field2Prop);
     $this->assertEquals(1, count($propAnnots));
     $this->assertTrue(isset($propAnnots['Doctrine\\Tests\\Common\\Annotations\\DummyJoinTable']));
     $joinTableAnnot = $propAnnots['Doctrine\\Tests\\Common\\Annotations\\DummyJoinTable'];
     $this->assertEquals(1, count($joinTableAnnot->joinColumns));
     $this->assertEquals(1, count($joinTableAnnot->inverseJoinColumns));
     $this->assertTrue($joinTableAnnot->joinColumns[0] instanceof DummyJoinColumn);
     $this->assertTrue($joinTableAnnot->inverseJoinColumns[0] instanceof DummyJoinColumn);
     $this->assertEquals('col1', $joinTableAnnot->joinColumns[0]->name);
     $this->assertEquals('col2', $joinTableAnnot->joinColumns[0]->referencedColumnName);
     $this->assertEquals('col3', $joinTableAnnot->inverseJoinColumns[0]->name);
     $this->assertEquals('col4', $joinTableAnnot->inverseJoinColumns[0]->referencedColumnName);
     $dummyAnnot = $reader->getMethodAnnotation($class->getMethod('getField1'), 'Doctrine\\Tests\\Common\\Annotations\\DummyAnnotation');
     $this->assertEquals('', $dummyAnnot->dummyValue);
     $this->assertEquals(array(1, 2, 'three'), $dummyAnnot->value);
     $dummyAnnot = $reader->getPropertyAnnotation($class->getProperty('field1'), 'Doctrine\\Tests\\Common\\Annotations\\DummyAnnotation');
     $this->assertEquals('fieldHello', $dummyAnnot->dummyValue);
     $classAnnot = $reader->getClassAnnotation($class, 'Doctrine\\Tests\\Common\\Annotations\\DummyAnnotation');
     $this->assertEquals('hello', $classAnnot->dummyValue);
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:41,代码来源:AnnotationReaderTest.php

示例12: fromReflection

 public static function fromReflection(ReflectionProperty $reflection = NULL)
 {
     if (!defined('PHP_VERSION_ID')) {
         $v = explode('.', PHP_VERSION);
         define('PHP_VERSION_ID', $v[0] * 10000 + $v[1] * 100 + $v[2]);
     }
     if ($reflection === null) {
         return null;
     }
     if (func_num_args() > 1) {
         $stack = func_get_arg(1);
     } else {
         $stack = new \ArrayObject();
     }
     $stackExpression = $reflection->getDeclaringClass()->getName() . '::' . $reflection->getName();
     if (isset($stack[$stackExpression])) {
         return $stack[$stackExpression];
     }
     $stack[$stackExpression] = $instance = new Property($reflection);
     if (func_num_args() > 2) {
         $reader = func_get_arg(2);
     } else {
         $reader = new AnnotationReader();
     }
     if (func_num_args() > 3) {
         $phpParser = func_get_arg(3);
     } else {
         $phpParser = new PhpParser();
     }
     $instance->name = $reflection->getName();
     $instance->public = $reflection->isPublic();
     $instance->private = $reflection->isPrivate();
     $instance->protected = $reflection->isProtected();
     $instance->static = $reflection->isStatic();
     $instance->default = $reflection->isDefault();
     $instance->modifiers = $reflection->getModifiers();
     $instance->docComment = $reflection->getDocComment();
     $instance->annotations = $reader->getPropertyAnnotations($reflection);
     $instance->declaringClass = Type::fromReflection($reflection->getDeclaringClass() ? $reflection->getDeclaringClass() : null, $stack, $reader, $phpParser);
     $defaultProperties = $reflection->getDeclaringClass()->getDefaultProperties();
     if (isset($defaultProperties[$instance->name])) {
         $instance->defaultValue = $defaultProperties[$instance->name];
     }
     if (preg_match('/@var\\s+([a-zA-Z0-9\\\\\\[\\]_]+)/', $instance->docComment, $m)) {
         $typeString = $m[1];
     }
     if (isset($typeString)) {
         $instance->type = MixedType::fromString($typeString, $stack, $reader, $phpParser, $instance->declaringClass);
     } else {
         $instance->type = MixedType::getInstance();
     }
     return $instance;
 }
开发者ID:jakubkulhan,项目名称:meta,代码行数:53,代码来源:Property.php

示例13: getPropertyRule

 /**
  * Get BuilderDefinition from entity property
  *
  * @param string $propertyName
  * @param bool $fillValues
  * @return BuilderDefinition|null
  * @throws InvalidStateException
  */
 private function getPropertyRule($propertyName, $fillValues = TRUE)
 {
     $property = $this->entityReflection->getProperty($propertyName);
     $annotations = $this->annotationReader->getPropertyAnnotations($property);
     $rule = new BuilderDefinition($propertyName);
     foreach ($annotations as $annotation) {
         switch (get_class($annotation)) {
             case 'Doctrine\\ORM\\Mapping\\Column':
                 if ($this->getEntityPrimaryKeyName($this->entity) === $propertyName) {
                     $rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_HIDDEN);
                     $rule->setRequired(FALSE);
                 } else {
                     $type = BuilderDefinition::COMPONENT_TYPE_TEXT;
                     $rule->setRequired(!$annotation->nullable);
                     /** @var Column $annotation */
                     if ($annotation->type === 'boolean') {
                         $type = BuilderDefinition::COMPONENT_TYPE_CHECKBOX;
                     }
                     // is numeric?
                     if ($annotation->type === 'integer' || $annotation->type === 'float' || $annotation->type === 'bigint' || $annotation->type === 'decimal' || $annotation->type === 'smallint') {
                         $rule->addValidationRule(Form::NUMERIC, 'This is required in numeric format', TRUE);
                     }
                     $rule->setComponentType($type);
                 }
                 break;
             case 'Doctrine\\ORM\\Mapping\\ManyToOne':
                 /** @var ManyToOne $annotation */
                 $rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_SELECT);
                 if ($fillValues) {
                     $rule->setValues($this->getPossibleValues($annotation->targetEntity));
                 }
                 $rule->setTargetEntity($annotation->targetEntity);
                 $rule->setRequired(TRUE);
                 break;
             case 'Doctrine\\ORM\\Mapping\\ManyToMany':
                 /** @var OneToMany $annotation */
                 $rule->setComponentType(BuilderDefinition::COMPONENT_TYPE_MULTI_SELECT);
                 if ($fillValues) {
                     $rule->setValues($this->getPossibleValues($annotation->targetEntity));
                 }
                 $rule->setRequired(TRUE);
                 $rule->setTargetEntity($annotation->targetEntity);
                 break;
             case 'Doctrine\\ORM\\Mapping\\JoinColumn':
                 /** @var JoinColumn $annotation */
                 $rule->setRequired(!$annotation->nullable);
                 break;
         }
     }
     return $rule->getComponentType() === NULL ? NULL : $rule;
 }
开发者ID:KennyDaren,项目名称:doctrine-mapper,代码行数:59,代码来源:FormBuilder.php

示例14: getAnnotationValidator

 /**
  * Get all annotation and add validators
  */
 protected function getAnnotationValidator()
 {
     $reader = new AnnotationReader();
     $classReflection = new \ReflectionClass($this->object);
     $propertiesReflection = $classReflection->getProperties();
     foreach ($propertiesReflection as $property) {
         $annotations = $reader->getPropertyAnnotations($property);
         $propertyName = $property->getName();
         foreach ($annotations as $annotation) {
             if ($annotation instanceof ValidatorInterface) {
                 $this->addValidator($propertyName, $annotation);
             }
         }
     }
 }
开发者ID:macfja,项目名称:validator,代码行数:18,代码来源:AnnotationValidator.php

示例15: getJsonSchema

 public static function getJsonSchema()
 {
     $reader = new AnnotationReader();
     $schema = array();
     $reflection = new \ReflectionClass(static::class);
     foreach ($reflection->getProperties() as $property) {
         $annotations = $reader->getPropertyAnnotations($property);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Property) {
                 var_dump($annotation);
             } else {
                 var_dump($annotation);
             }
         }
     }
 }
开发者ID:hielsnoppe,项目名称:php-goodies,代码行数:16,代码来源:JsonSerializable.php


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