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


PHP ClassMetadata::getReflectionClass方法代码示例

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


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

示例1: loadClassMetadata

 /**
  * Event triggered during metadata loading
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $this->classMetadata = $eventArgs->getClassMetadata();
     $reflectionClass = $this->classMetadata->getReflectionClass();
     if (null === $reflectionClass) {
         return;
     }
     if ($this->hasMethod($reflectionClass, 'updateTimestamps')) {
         $this->addLifecycleCallbacks();
         $this->mapFields();
     }
 }
开发者ID:raizeta,项目名称:WellCommerce,代码行数:17,代码来源:TimestampableSubscriber.php

示例2: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         if ($timestampable = $this->reader->getPropertyAnnotation($property, self::TIMESTAMPABLE)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->name}");
             }
             if (!in_array($timestampable->on, array('update', 'create', 'change'))) {
                 throw new InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$meta->name}");
             }
             if ($timestampable->on == 'change') {
                 if (!isset($timestampable->field) || !isset($timestampable->value)) {
                     throw new InvalidMappingException("Missing parameters on property - {$field}, field and value must be set on [change] trigger in class - {$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:robertowest,项目名称:CuteFlow-V4,代码行数:33,代码来源:Annotation.php

示例3: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // position
         if ($position = $this->reader->getPropertyAnnotation($property, self::POSITION)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find 'position' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->name}");
             }
             $config['position'] = $field;
         }
         // group
         if ($group = $this->reader->getPropertyAnnotation($property, self::GROUP)) {
             $field = $property->getName();
             if (!$meta->hasField($field) && !$meta->hasAssociation($field)) {
                 throw new InvalidMappingException("Unable to find 'group' - [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!isset($config['groups'])) {
                 $config['groups'] = array();
             }
             $config['groups'][] = $field;
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:35,代码来源:Annotation.php

示例4: isResource

 /**
  * @param ClassMetadata $metadata
  *
  * @return bool
  */
 protected function isResource(ClassMetadata $metadata)
 {
     if (!($reflClass = $metadata->getReflectionClass())) {
         return false;
     }
     return $reflClass->implementsInterface(PersistableInterface::class);
 }
开发者ID:superdesk,项目名称:web-publisher,代码行数:12,代码来源:AbstractDoctrineSubscriber.php

示例5: testInitializedProxyUnserialization

 public function testInitializedProxyUnserialization()
 {
     // persister will retrieve the lazy object itself, so that we don't have to re-define all field values
     $this->proxyLoader->expects($this->once())->method('load')->will($this->returnValue($this->lazyObject));
     $this->lazyObject->__setInitializer($this->getSuggestedInitializerImplementation());
     $this->lazyObject->__load();
     $serialized = serialize($this->lazyObject);
     $reflClass = $this->lazyLoadableObjectMetadata->getReflectionClass();
     /* @var $unserialized LazyLoadableObject|Proxy */
     $unserialized = unserialize($serialized);
     $this->assertTrue($unserialized->__isInitialized(), 'serialization didn\'t cause intialization');
     // Checking transient fields
     $this->assertSame('publicTransientFieldValue', $unserialized->publicTransientField, 'transient fields are kept');
     $protectedTransientField = $reflClass->getProperty('protectedTransientField');
     $protectedTransientField->setAccessible(true);
     $this->assertSame('protectedTransientFieldValue', $protectedTransientField->getValue($unserialized), 'transient fields are kept');
     // Checking persistent fields
     $this->assertSame('publicPersistentFieldValue', $unserialized->publicPersistentField, 'persistent fields are kept');
     $protectedPersistentField = $reflClass->getProperty('protectedPersistentField');
     $protectedPersistentField->setAccessible(true);
     $this->assertSame('protectedPersistentFieldValue', $protectedPersistentField->getValue($unserialized), 'persistent fields are kept');
     // Checking identifiers
     $this->assertSame('publicIdentifierFieldValue', $unserialized->publicIdentifierField, 'identifiers are kept');
     $protectedIdentifierField = $reflClass->getProperty('protectedIdentifierField');
     $protectedIdentifierField->setAccessible(true);
     $this->assertSame('protectedIdentifierFieldValue', $protectedIdentifierField->getValue($unserialized), 'identifiers are kept');
     // Checking associations
     $this->assertSame('publicAssociationValue', $unserialized->publicAssociation, 'associations are kept');
     $protectedAssociationField = $reflClass->getProperty('protectedAssociation');
     $protectedAssociationField->setAccessible(true);
     $this->assertSame('protectedAssociationValue', $protectedAssociationField->getValue($unserialized), 'associations are kept');
 }
开发者ID:sanborino,项目名称:clinica,代码行数:32,代码来源:ProxyLogicTest.php

示例6: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     $config['fields'] = array();
     $config['fields_delete'] = array();
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         $field = null;
         if ($file = $this->reader->getPropertyAnnotation($property, self::FILE)) {
             $field['name'] = $property->getName();
             $field['dir'] = CMSCore::init()->getUploadsDir() . '/' . $file->dir;
             if (!$meta->hasField($field['name'])) {
                 throw new InvalidMappingException("Unable to find timestampable [{$field}] as mapped property in entity - {$meta->name}");
             }
         }
         // if ($fileDelete = $this->reader->getPropertyAnnotation($property, self::FILE_DELETE)) {
         //
         // $config['fields_delete'][] = $property->getName();
         //
         // }
         if ($field) {
             $config['fields'][] = $field;
         }
     }
 }
开发者ID:GrifiS,项目名称:Symfony2CMS,代码行数:31,代码来源:Annotation.php

示例7: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // class annotations
     if ($annot = $this->reader->getClassAnnotation($class, self::LOGGABLE)) {
         $config['loggable'] = true;
         if ($annot->logEntryClass) {
             if (!class_exists($annot->logEntryClass)) {
                 throw new InvalidMappingException("LogEntry class: {$annot->logEntryClass} does not exist.");
             }
             $config['logEntryClass'] = $annot->logEntryClass;
         }
     }
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // versioned property
         if ($versioned = $this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
             $field = $property->getName();
             if ($meta->isCollectionValuedAssociation($field)) {
                 throw new InvalidMappingException("Cannot versioned [{$field}] as it is collection in object - {$meta->name}");
             }
             // fields cannot be overrided and throws mapping exception
             $config['versioned'][] = $field;
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:32,代码来源:Annotation.php

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

示例9: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  * @throws \Doctrine\ORM\ODMAdapter\Exception\MappingException
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /** @var $class \Doctrine\ORM\ODMAdapter\Mapping\ClassMetadata */
     $reflClass = $metadata->getReflectionClass();
     $documentAnnots = array();
     foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
         foreach ($this->entityAnnotationClasses as $annotClass => $i) {
             if ($annot instanceof $annotClass) {
                 $documentAnnots[$i] = $annot;
             }
         }
     }
     if (!$documentAnnots) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     $metadata->className = $className;
     foreach ($reflClass->getProperties() as $property) {
         if ($metadata->className !== $property->getDeclaringClass()->getName()) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         foreach ($this->reader->getPropertyAnnotations($property) as $propertyAnnotation) {
             if ($propertyAnnotation instanceof Adapter\ReferencePhpcr) {
                 $mapping['type'] = Reference::PHPCR;
                 $this->extractReferencedObjects($propertyAnnotation, $metadata, $className, $mapping);
             }
             if ($propertyAnnotation instanceof Adapter\ReferenceDbalOrm) {
                 $mapping['type'] = Reference::DBAL_ORM;
                 $this->extractReferencedObjects($propertyAnnotation, $metadata, $className, $mapping);
             }
         }
     }
 }
开发者ID:joschi127,项目名称:DoctrineOrmOdmAdapter,代码行数:42,代码来源:AnnotationDriver.php

示例10: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /** @var $class ClassMetadataInfo */
     $reflClass = $metadata->getReflectionClass();
     if ($entityAnnot = $this->reader->getClassAnnotation($reflClass, 'Pasinter\\OHM\\Mapping\\Annotations\\Entity')) {
         $metadata->database = $entityAnnot->database;
     }
     // Evaluate annotations on properties/fields
     foreach ($reflClass->getProperties() as $property) {
         if ($fieldAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Field')) {
             $mapping = $this->fieldToArray($property->getName(), $fieldAnnot);
             if ($this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\Id')) {
                 $mapping['id'] = true;
             }
             $metadata->mapField($mapping);
         } elseif ($referenceOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceOne')) {
             $mapping = $this->referenceOneToArray($property->getName(), $referenceOneAnnot);
             $metadata->mapOneReference($mapping);
         } elseif ($referenceManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\ReferenceMany')) {
             $mapping = $this->referenceManyToArray($property->getName(), $referenceManyAnnot);
             $metadata->mapManyReference($mapping);
         } elseif ($embedOneAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedOne')) {
             $mapping = $this->embedOneToArray($property->getName(), $embedOneAnnot);
             $metadata->mapOneEmbed($mapping);
         } elseif ($embedManyAnnot = $this->reader->getPropertyAnnotation($property, 'Pasinter\\OHM\\Mapping\\Annotations\\EmbedMany')) {
             $mapping = $this->embedManyToArray($property->getName(), $embedManyAnnot);
             $metadata->mapManyEmbed($mapping);
         }
     }
 }
开发者ID:pasinter,项目名称:redis-ohm,代码行数:33,代码来源:AnnotationDriver.php

示例11: readExtendedMetadata

 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     // load our available annotations
     require_once __DIR__ . '/../Annotations.php';
     $reader = new AnnotationReader();
     // set annotation namespace and alias
     //$reader->setAnnotationNamespaceAlias('Gedmo\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
     $class = $meta->getReflectionClass();
     // check only property annotations
     foreach ($class->getProperties() as $property) {
         // skip inherited properties
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // now lets check if property has our annotation
         if ($encode = $reader->getPropertyAnnotation($property, 'Gedmo\\Mapping\\Mock\\Extension\\Encoder\\Mapping\\Encode')) {
             $field = $property->getName();
             // check if field is mapped
             if (!$meta->hasField($field)) {
                 throw new \Exception("Field is not mapped as object property");
             }
             // allow encoding only strings
             if (!in_array($encode->type, array('sha1', 'md5'))) {
                 throw new \Exception("Invalid encoding type supplied");
             }
             // validate encoding type
             $mapping = $meta->getFieldMapping($field);
             if ($mapping['type'] != 'string') {
                 throw new \Exception("Only strings can be encoded");
             }
             // store the metadata
             $config['encode'][$field] = array('type' => $encode->type, 'secret' => $encode->secret);
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:35,代码来源:Annotation.php

示例12: hydrate

 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array  $data
  * @param  object $object
  * @throws \Exception
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     $this->metadata = $this->objectManager->getClassMetadata(get_class($object));
     $object = $this->tryConvertArrayToObject($data, $object);
     foreach ($data as $field => &$value) {
         $value = $this->hydrateValue($field, $value);
         if ($value === null) {
             continue;
         }
         // @todo DateTime (and other types) conversion should be handled by doctrine itself in future
         if (in_array($this->metadata->getTypeOfField($field), array('datetime', 'time', 'date'))) {
             if (is_int($value)) {
                 $dt = new DateTime();
                 $dt->setTimestamp($value);
                 $value = $dt;
             } elseif (is_string($value)) {
                 $value = new DateTime($value);
             }
         }
         if ($this->metadata->hasAssociation($field)) {
             $target = $this->metadata->getAssociationTargetClass($field);
             if ($this->metadata->isSingleValuedAssociation($field)) {
                 $value = $this->toOne($value, $target);
             } elseif ($this->metadata->isCollectionValuedAssociation($field)) {
                 $value = $this->toMany($value, $target);
                 // Automatically merge collections using helper utility
                 $propertyRefl = $this->metadata->getReflectionClass()->getProperty($field);
                 $propertyRefl->setAccessible(true);
                 $previousValue = $propertyRefl->getValue($object);
                 $value = CollectionUtils::intersectUnion($previousValue, $value);
             }
         }
     }
     return $this->hydrator->hydrate($data, $object);
 }
开发者ID:rrmodi88,项目名称:DoctrineModule,代码行数:43,代码来源:DoctrineObject.php

示例13: appendConfigurationFromMetadata

 protected function appendConfigurationFromMetadata(ClassMetadata $metadata, &$configuration)
 {
     $serializationFilePath = $this->resolvePath($metadata->getReflectionClass());
     if ($this->filesystem->exists($serializationFilePath)) {
         $content = file_get_contents($serializationFilePath);
         $configuration = array_replace_recursive($configuration, $this->parseContent($content));
     }
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:8,代码来源:SerializationCacheWarmer.php

示例14: readExtendedMetadata

 /**
  * {@inheritDoc}
  */
 public function readExtendedMetadata(ClassMetadata $meta, array &$config)
 {
     $class = $meta->getReflectionClass();
     // property annotations
     foreach ($class->getProperties() as $property) {
         if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) {
             continue;
         }
         // slug property
         if ($slug = $this->reader->getPropertyAnnotation($property, self::SLUG)) {
             $field = $property->getName();
             if (!$meta->hasField($field)) {
                 throw new InvalidMappingException("Unable to find slug [{$field}] as mapped property in entity - {$meta->name}");
             }
             if (!$this->isValidField($meta, $field)) {
                 throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
             }
             // process slug handlers
             $handlers = array();
             if (is_array($slug->handlers) && $slug->handlers) {
                 foreach ($slug->handlers as $handler) {
                     if (!$handler instanceof SlugHandler) {
                         throw new InvalidMappingException("SlugHandler: {$handler} should be instance of SlugHandler annotation in entity - {$meta->name}");
                     }
                     if (!strlen($handler->class)) {
                         throw new InvalidMappingException("SlugHandler class: {$handler->class} should be a valid class name in entity - {$meta->name}");
                     }
                     $class = $handler->class;
                     $handlers[$class] = array();
                     foreach ((array) $handler->options as $option) {
                         if (!$option instanceof SlugHandlerOption) {
                             throw new InvalidMappingException("SlugHandlerOption: {$option} should be instance of SlugHandlerOption annotation in entity - {$meta->name}");
                         }
                         if (!strlen($option->name)) {
                             throw new InvalidMappingException("SlugHandlerOption name: {$option->name} should be valid name in entity - {$meta->name}");
                         }
                         $handlers[$class][$option->name] = $option->value;
                     }
                     $class::validate($handlers[$class], $meta);
                 }
             }
             // process slug fields
             if (empty($slug->fields) || !is_array($slug->fields)) {
                 throw new InvalidMappingException("Slug must contain at least one field for slug generation in class - {$meta->name}");
             }
             foreach ($slug->fields as $slugField) {
                 if (!$meta->hasField($slugField)) {
                     throw new InvalidMappingException("Unable to find slug [{$slugField}] as mapped property in entity - {$meta->name}");
                 }
                 if (!$this->isValidField($meta, $slugField)) {
                     throw new InvalidMappingException("Cannot use field - [{$slugField}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->name}");
                 }
             }
             // set all options
             $config['slugs'][$field] = array('fields' => $slug->fields, 'slug' => $field, 'style' => $slug->style, 'updatable' => $slug->updatable, 'unique' => $slug->unique, 'separator' => $slug->separator, 'handlers' => $handlers);
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:61,代码来源:Annotation.php

示例15: mapTranslation

 /**
  * {@inheritDoc}
  */
 public function mapTranslation(ClassMetadata $meta, $translatableClassName)
 {
     $rc = $meta->getReflectionClass();
     if (!$rc->hasProperty('object') || $meta->hasAssociation('object') || !$rc->isSubclassOf($this->personalTranslation)) {
         return;
     }
     $namingStrategy = $this->getObjectManager()->getConfiguration()->getNamingStrategy();
     $meta->mapManyToOne(['targetEntity' => $translatableClassName, 'fieldName' => 'object', 'inversedBy' => 'translations', 'isOwningSide' => true, 'joinColumns' => [['name' => $namingStrategy->joinColumnName('object'), 'referencedColumnName' => $namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']]]);
 }
开发者ID:coolms,项目名称:doctrine,代码行数:12,代码来源:ORM.php


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