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


PHP AnnotationReader::getPropertyAnnotation方法代码示例

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


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

示例1: guessType

 /**
  * {@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);
 }
开发者ID:snovichkov,项目名称:TreeChoiceBundle,代码行数:31,代码来源:TreeChoiceTypeGuesser.php

示例2: getTemplateDataForModel

 protected function getTemplateDataForModel($model)
 {
     $data = ['name' => Helper::get()->shortName($model), 'slug' => Helper::get()->slugify($model), 'properties' => []];
     $reflectionClass = new \ReflectionClass($model);
     $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
     $reader = new AnnotationReader();
     foreach ($properties as $property) {
         $name = $property->getName();
         $type = null;
         $targetEntity = null;
         $mappedBySlug = null;
         $propertyDefinition = ['name' => $name];
         if (($fieldAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Field')) !== null) {
             $type = $fieldAnnotation->type;
         } elseif (($referenceOneAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceOne')) !== null) {
             $name .= '.id';
             $type = 'reference';
             $targetEntity = Helper::get()->shortName($referenceOneAnnotation->targetDocument);
         } elseif (($referenceManyAnnotation = $reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ReferenceMany')) !== null) {
             $type = 'referenced_list';
             $targetEntity = Helper::get()->shortName($referenceManyAnnotation->targetDocument);
             $mappedBySlug = Helper::get()->slugify($referenceManyAnnotation->mappedBy, false);
         } elseif ($reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Id') === null) {
             continue;
         }
         $propertyDefinition['name'] = $name;
         $propertyDefinition['type'] = $type;
         if ($targetEntity) {
             $propertyDefinition[$type] = ['targetEntity' => $targetEntity, 'targetEntitySlug' => Helper::get()->slugify($targetEntity), 'mappedBySlug' => $mappedBySlug];
         }
         $data['properties'][] = $propertyDefinition;
     }
     return $data;
 }
开发者ID:100hz,项目名称:hive-console,代码行数:34,代码来源:ScaffoldUICommand.php

示例3: getProperties

 protected function getProperties($object)
 {
     $reflClass = new \ReflectionClass($object);
     $codeAnnotation = $this->annotationReader->getClassAnnotation($reflClass, Segment::class);
     if (!$codeAnnotation) {
         throw new AnnotationMissing(sprintf("Missing @Segment annotation for class %", $reflClass->getName()));
     }
     $properties = [$codeAnnotation->value];
     foreach ($reflClass->getProperties() as $propRefl) {
         $propRefl->setAccessible(true);
         /** @var SegmentPiece $isSegmentPiece */
         $isSegmentPiece = $this->annotationReader->getPropertyAnnotation($propRefl, SegmentPiece::class);
         if ($isSegmentPiece) {
             if (!$isSegmentPiece->parts) {
                 $properties[$isSegmentPiece->position] = $propRefl->getValue($object);
             } else {
                 $parts = $isSegmentPiece->parts;
                 $value = $propRefl->getValue($object);
                 $valuePieces = [];
                 foreach ($parts as $key => $part) {
                     if (is_integer($key)) {
                         $partName = $part;
                     } else {
                         $partName = $key;
                     }
                     $valuePieces[] = isset($value[$partName]) ? $value[$partName] : null;
                 }
                 $properties[$isSegmentPiece->position] = $this->weedOutEmpty($valuePieces);
             }
         }
     }
     $properties = $this->weedOutEmpty($properties);
     return $properties;
 }
开发者ID:progrupa,项目名称:edifact,代码行数:34,代码来源:AnnotationPrinter.php

示例4: onSerializerPreDeserialize

 public function onSerializerPreDeserialize(PreDeserializeEvent $e)
 {
     $className = $e->getType();
     $className = $className['name'];
     /** Handle ArrayCollection or array JMS type. */
     if ($className == "ArrayCollection" || $className == "array") {
         $className = $e->getType();
         $className = $className['params'][0]['name'];
     }
     $classMetadata = $e->getContext()->getMetadataFactory()->getMetadataForClass($className);
     /** @var PropertyMetadata $propertyMetadata */
     foreach ($classMetadata->propertyMetadata as $propertyMetadata) {
         if ($propertyMetadata->reflection === null) {
             continue;
         }
         /** @var JoinColumn $joinColumnAnnotation */
         $joinColumnAnnotation = $this->reader->getPropertyAnnotation($propertyMetadata->reflection, 'Doctrine\\ORM\\Mapping\\JoinColumn');
         if ($joinColumnAnnotation !== null) {
             if (array_key_exists($joinColumnAnnotation->name, $e->getData())) {
                 $idValue = $e->getData();
                 $idValue = $idValue[$joinColumnAnnotation->name];
                 if ($idValue !== null) {
                     $e->setData($e->getData() + array($propertyMetadata->name => array('id' => $idValue)));
                 } else {
                     $e->setData($e->getData() + array($propertyMetadata->name => null));
                 }
             }
         }
     }
 }
开发者ID:tecnocreaciones,项目名称:extjs-bundle,代码行数:30,代码来源:DeserializationAssociateRelationship.php

示例5: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $entityAnnot = $this->reader->getClassAnnotation($class, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Entity');
     if (!$entityAnnot) {
         throw new \InvalidArgumentException($metadata->name . ' is not a valid key-value-store entity.');
     }
     $metadata->storageName = $entityAnnot->storageName;
     // Evaluate annotations on properties/fields
     foreach ($class->getProperties() as $property) {
         $idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Id');
         $transientAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\KeyValueStore\\Mapping\\Annotations\\Transient');
         if ($idAnnot) {
             $metadata->mapIdentifier($property->getName());
         } elseif ($transientAnnot) {
             $metadata->skipTransientField($property->getName());
         } else {
             $metadata->mapField(['fieldName' => $property->getName()]);
         }
     }
 }
开发者ID:nicktacular,项目名称:KeyValueStore,代码行数:32,代码来源:AnnotationDriver.php

示例6: setBriefProperty

 public function setBriefProperty($object, $name, $value, $expectedClass = null)
 {
     $reflection = new \ReflectionClass($object);
     if (!$reflection->hasProperty($name)) {
         return false;
     }
     $property = $reflection->getProperty($name);
     $property->setAccessible(true);
     if ($value instanceof Resource) {
         $value = $value->getUri();
         $annotation = $this->annotationReader->getPropertyAnnotation($property, 'Soil\\CommentsDigestBundle\\Annotation\\Entity');
         if ($annotation) {
             $expectedClass = $annotation->value ?: true;
             var_dump($expectedClass);
             try {
                 $entity = $this->resolver->getEntityForURI($value, $expectedClass);
             } catch (\Exception $e) {
                 $entity = null;
                 echo "Problem with discovering" . PHP_EOL;
                 echo $e->getMessage() . PHP_EOL;
                 var_dump($value, $expectedClass);
                 echo PHP_EOL;
                 //FIXME: Add logging
             }
             if ($entity) {
                 $value = $entity;
             }
         }
     } elseif ($value instanceof Literal) {
         $value = $value->getValue();
     }
     $property->setValue($object, $value);
 }
开发者ID:soilby,项目名称:comments-digest-bundle,代码行数:33,代码来源:BriefPropertySetter.php

示例7: buildMetaData

 /**
  * buildMetaData
  *
  * build the columns and other metadata for this class
  */
 protected function buildMetaData()
 {
     $columnArray = array();
     $className = $this->getClassName($this->tableConfig);
     $refl = new \ReflectionClass($className);
     $properties = $refl->getProperties();
     foreach ($properties as $property) {
         $column = $this->reader->getPropertyAnnotation($property, $this->columnNs);
         if (!empty($column)) {
             if (!isset($column->source)) {
                 throw new InvalidArgumentException('DataTables requires a "source" attribute be provided for a column');
             }
             if (!isset($column->name)) {
                 throw new InvalidArgumentException('DataTables requires a "name" attribute be provided for a column');
             }
             // check for default
             $default = $this->reader->getPropertyAnnotation($property, $this->defaultSortNs);
             if (!empty($default)) {
                 $column->defaultSort = true;
             }
             // check for formatting
             $format = $this->reader->getPropertyAnnotation($property, $this->formatNs);
             if (!empty($format)) {
                 if (!isset($format->dataFields)) {
                     throw new InvalidArgumentException('DataTables requires a "dataFields" attribute be provided for a column formatter');
                 }
                 $column->format = $format;
             }
             $this->columns[] = $column;
             $columnArray[$column->source] = $column->name;
         }
     }
     $this->table->setColumns($columnArray);
     $this->table->setMetaData(array('table' => $this->tableConfig, 'columns' => $this->columns));
 }
开发者ID:aeyoll,项目名称:DataTablesBundle,代码行数:40,代码来源:AnnotationTableBuilder.php

示例8: addProperties

 /**
  * 
  * @param \ReflectionClass $class
  * @param Object $c_ann
  */
 public function addProperties(\ReflectionClass $class, $c_ann)
 {
     if ($this->isListener($c_ann)) {
         foreach ($class->getProperties() as $ref_prop) {
             $annotation = $this->reader->getPropertyAnnotation($ref_prop, 'DIPcom\\AnnEvents\\Mapping\\On');
             if ($annotation) {
                 $this->guideline->addListener($ref_prop, $annotation);
             }
         }
     }
 }
开发者ID:dipcom,项目名称:annevents,代码行数:16,代码来源:AnnEventsExtension.php

示例9: shouldReceiveAnnotation

 /**
  */
 public function shouldReceiveAnnotation()
 {
     $reader = new AnnotationReader();
     $refObj = new \ReflectionClass(Article::class);
     $titleProp = $refObj->getProperty('title');
     $bodyProp = $refObj->getProperty('body');
     $titleAnnotation = $reader->getPropertyAnnotation($titleProp, 'Vertigolabs\\DoctrineFullTextPostgres\\ORM\\Mapping\\TsVector');
     $bodyAnnotation = $reader->getPropertyAnnotation($bodyProp, 'Vertigolabs\\DoctrineFullTextPostgres\\ORM\\Mapping\\TsVector');
     $this->assertNotNull($titleAnnotation, 'TsVector annotation not found for title');
     $this->assertNotNull($bodyAnnotation, 'TsVector annotation not found for body');
 }
开发者ID:jbinfo,项目名称:DoctrineFullTextPostrgres,代码行数:13,代码来源:TsVectorTest.php

示例10: 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

示例11: readExtendedMetadata

 /**
  * (non-PHPdoc)
  * @see Gedmo\Mapping.Driver::readExtendedMetadata()
  */
 public function readExtendedMetadata(ClassMetadataInfo $meta, array &$config)
 {
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     $reader->setAnnotationNamespaceAlias('Gedmo\\Timestampable\\Mapping\\', 'gedmo');
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || $meta->isInheritedAssociation($property->name)) {
             continue;
         }
         if ($timestampable = $reader->getPropertyAnnotation($property, self::ANNOTATION_TIMESTAMPABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw MappingException::fieldMustBeMapped($field, $meta->name);
             }
             if (!$this->_isValidField($meta, $field)) {
                 throw MappingException::notValidFieldType($field, $meta->name);
             }
             if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
                 throw MappingException::triggerTypeInvalid($field, $meta->name);
             }
             if ($timestampable->on == 'change') {
                 if (!isset($timestampable->field) || !isset($timestampable->value)) {
                     throw MappingException::parametersMissing($field, $meta->name);
                 }
                 $field = array('field' => $field, 'trackedField' => $timestampable->field, 'value' => $timestampable->value);
             }
             // properties are unique and mapper checks that, no risk here
             $config[$timestampable->on][] = $field;
         }
     }
 }
开发者ID:jgat2012,项目名称:hp_oms,代码行数:37,代码来源:Annotation.php

示例12: getRelationships

 /**
  * Get all relationships in the entity
  *
  * @return Relationship[]
  */
 public function getRelationships()
 {
     $r = [];
     $properties = $this->reflection_obj->getProperties();
     foreach ($properties as $property) {
         /** @var OneToOne $oto */
         $oto = $this->annotation_reader->getPropertyAnnotation($property, self::OTO_ANNOTATION);
         if ($oto) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::ONETOONE(), $oto);
         }
         /** @var OneToMany $otm */
         $otm = $this->annotation_reader->getPropertyAnnotation($property, self::OTM_ANNOTATION);
         if ($otm) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::ONETOMANY(), $otm);
         }
         /** @var ManyToOne $mto */
         $mto = $this->annotation_reader->getPropertyAnnotation($property, self::MTO_ANNOTATION);
         if ($mto) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::MANYTOONE(), $mto);
         }
         /** @var ManyToMany $mtm */
         $mtm = $this->annotation_reader->getPropertyAnnotation($property, self::MTM_ANNOTATION);
         if ($mtm) {
             $r[] = $this->createRelationship($property->getName(), RelationshipType::MANYTOMANY(), $mtm);
         }
     }
     return $r;
 }
开发者ID:andreyors,项目名称:orm,代码行数:33,代码来源:AnnotationMetadataParser.php

示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $model = $input->getArgument('model');
     $seeds = $input->getArgument('seeds');
     $io = new SymfonyStyle($input, $output);
     if (!class_exists($model)) {
         $io->error(array('The model you specified does not exist.', 'You can create a model with the "model:create" command.'));
         return 1;
     }
     $this->dm = $this->createDocumentManager($input->getOption('server'));
     $faker = Faker\Factory::create();
     AnnotationRegistry::registerAutoloadNamespace('Hive\\Annotations', dirname(__FILE__) . '/../../');
     $reflectionClass = new \ReflectionClass($model);
     $properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
     $reader = new AnnotationReader();
     for ($i = 0; $i < $seeds; $i++) {
         $instance = new $model();
         foreach ($properties as $property) {
             $name = $property->getName();
             $seed = $reader->getPropertyAnnotation($property, 'Hive\\Annotations\\Seed');
             if ($seed !== null) {
                 $fake = $seed->fake;
                 if (class_exists($fake)) {
                     $instance->{$name} = $this->createFakeReference($fake);
                 } else {
                     $instance->{$name} = $faker->{$seed->fake};
                 }
             }
         }
         $this->dm->persist($instance);
     }
     $this->dm->flush();
     $io->success(array("Created {$seeds} seeds for {$model}"));
 }
开发者ID:100hz,项目名称:hive-console,代码行数:37,代码来源:ModelSeedCommand.php

示例14: getEntityColumnType

 /**
  * Get Column Type of a model.
  *
  * @param $entity string Class name of the entity
  * @param $property string
  * @return string
  */
 public function getEntityColumnType($entity, $property)
 {
     $classRef = new \ReflectionClass($entity);
     $columnRef = null;
     $propertyRef = null;
     if ($classRef->hasProperty($property)) {
         $propertyRef = $classRef->getProperty($property);
         $columnRef = $this->annoReader->getPropertyAnnotation($propertyRef, 'Doctrine\\ORM\\Mapping\\Column');
     } else {
         /** Can not find the property on the class. Check the all the Column annotation */
         foreach ($classRef->getProperties() as $propertyRef) {
             $columnRef = $this->annoReader->getPropertyAnnotation($propertyRef, 'Doctrine\\ORM\\Mapping\\Column');
             if ($columnRef->name == $property) {
                 break;
             } else {
                 $columnRef = null;
             }
         }
     }
     if ($columnRef === null) {
         $idRef = $this->annoReader->getPropertyAnnotation($propertyRef, 'Doctrine\\ORM\\Mapping\\Id');
         if ($idRef !== null) {
             return "int";
         } else {
             return "string";
         }
     } else {
         return $this->getColumnType($columnRef->type);
     }
 }
开发者ID:VAndAl37,项目名称:extjs-bundle,代码行数:37,代码来源:GeneratorService.php

示例15: persist

 public function persist($entity)
 {
     $reflection = new \ReflectionClass($entity);
     $originURI = $entity->getOrigin();
     if (!$originURI) {
         throw new \Exception("Cannot persist entity, because origin URI is not defined");
     }
     $sparql = '';
     $annotationReader = new AnnotationReader();
     $iri = $annotationReader->getClassAnnotation($reflection, 'Soil\\DiscoverBundle\\Annotation\\Iri');
     if ($iri) {
         $iri = $iri->value;
         $sparql .= "<{$originURI}> rdf:type {$iri} . " . PHP_EOL;
     }
     $props = $reflection->getProperties();
     foreach ($props as $prop) {
         $matchAnnotation = $annotationReader->getPropertyAnnotation($prop, 'Soil\\DiscoverBundle\\Annotation\\Iri');
         if ($matchAnnotation && $matchAnnotation->persist) {
             $match = $matchAnnotation->value;
             $prop->setAccessible(true);
             $value = $prop->getValue($entity);
             $sparql .= "<{$originURI}> {$match} <{$value}> . " . PHP_EOL;
         }
     }
     if ($sparql) {
         $this->logger->addInfo('Persisting: ');
         $this->logger->addInfo($sparql);
         $num = $this->endpoint->insert($sparql);
         $this->logger->addInfo('Return: ' . print_r($num, true));
         return $num;
     } else {
         return null;
     }
 }
开发者ID:soilby,项目名称:rdf-persistence-bundle,代码行数:34,代码来源:PersistenceService.php


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