當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。