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


PHP ClassMetadata::mapField方法代码示例

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


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

示例1: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\TestDocument1');
     $cm1->setCollection('group');
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'string'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'id' => true));
     // and a mapped association
     $cm1->mapOneEmbedded(array('fieldName' => 'other', 'targetDocument' => 'Other'));
     $cm1->mapOneEmbedded(array('fieldName' => 'association', 'targetDocument' => 'Other'));
     // SUT
     $cmf = new ClassMetadataFactoryTestSubject();
     $cmf->setMetadataFor('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\TestDocument1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(4, count($cm1->fieldMappings));
     // Go
     $cm1 = $cmf->getMetadataFor('Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\TestDocument1');
     $this->assertEquals('group', $cm1->collection);
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertTrue($cm1->hasField('name'));
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:26,代码来源:ClassMetadataFactoryTest.php

示例2: mapTranslation

 /**
  * Add mapping data to a translation entity.
  *
  * @param ClassMetadata $metadata
  */
 private function mapTranslation(ClassMetadata $metadata)
 {
     // In the case A -> B -> TranslationInterface, B might not have mapping defined as it
     // is probably defined in A, so in that case, we just return.
     if (!isset($this->configs[$metadata->name])) {
         return;
     }
     $metadata->mapManyToOne(array('fieldName' => 'translatable', 'targetEntity' => $this->configs[$metadata->name]['model'], 'inversedBy' => 'translations', 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false))));
     if (!$metadata->hasField('locale')) {
         $metadata->mapField(array('fieldName' => 'locale', 'type' => 'string', 'nullable' => false));
     }
     // Map unique index.
     $columns = array($metadata->getSingleAssociationJoinColumnName('translatable'), 'locale');
     if (!$this->hasUniqueConstraint($metadata, $columns)) {
         $constraints = isset($metadata->table['uniqueConstraints']) ? $metadata->table['uniqueConstraints'] : array();
         $constraints[$metadata->getTableName() . '_uniq_trans'] = array('columns' => $columns);
         $metadata->setPrimaryTable(array('uniqueConstraints' => $constraints));
     }
 }
开发者ID:eliberty,项目名称:SyliusTranslationBundle,代码行数:24,代码来源:ODMTranslatableListener.php

示例3: loadMetadata

 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE);
     $metadata->setCollection('cms_users');
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->setDiscriminatorField(array('fieldName' => 'discr'));
     $metadata->setDiscriminatorMap(array('default' => __CLASS__));
     $metadata->setDefaultDiscriminatorValue('default');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id'));
     $metadata->mapField(array('fieldName' => 'version', 'type' => 'int', 'version' => true));
     $metadata->mapField(array('fieldName' => 'lock', 'type' => 'int', 'lock' => true));
     $metadata->mapField(array('fieldName' => 'name', 'name' => 'username', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'mysqlProfileId', 'type' => 'integer'));
     $metadata->mapOneReference(array('fieldName' => 'address', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Address', 'cascade' => array(0 => 'remove')));
     $metadata->mapManyReference(array('fieldName' => 'phonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber'), 'defaultDiscriminatorValue' => 'home'));
     $metadata->mapManyReference(array('fieldName' => 'morePhoneNumbers', 'name' => 'more_phone_numbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber'));
     $metadata->mapManyReference(array('fieldName' => 'groups', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach')));
     $metadata->mapOneEmbedded(array('fieldName' => 'embeddedPhonenumber', 'name' => 'embedded_phone_number'));
     $metadata->mapManyEmbedded(array('fieldName' => 'otherPhonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber'), 'defaultDiscriminatorValue' => 'home'));
     $metadata->addIndex(array('username' => 'desc'), array('unique' => true, 'dropDups' => false));
     $metadata->addIndex(array('email' => 'desc'), array('unique' => true, 'dropDups' => true));
     $metadata->addIndex(array('mysqlProfileId' => 'desc'), array('unique' => true, 'dropDups' => true));
     $metadata->addIndex(array('createdAt' => 'asc'), array('expireAfterSeconds' => 3600));
     $metadata->setShardKey(array('name' => 'asc'), array('unique' => true, 'numInitialChunks' => 4096));
 }
开发者ID:dominium,项目名称:mongodb-odm,代码行数:28,代码来源:AbstractMappingDriverTest.php

示例4: testDuplicateFieldAndAssocationMapping2_ThrowsException

 public function testDuplicateFieldAndAssocationMapping2_ThrowsException()
 {
     $cm = new ClassMetadata('Documents\\CmsUser');
     $cm->mapOneEmbedded(array('fieldName' => 'name', 'targetDocument' => 'CmsUser'));
     $this->setExpectedException('Doctrine\\ODM\\MongoDB\\MongoDBException');
     $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name'));
 }
开发者ID:roed,项目名称:mongodb-odm,代码行数:7,代码来源:ClassMetadataTest.php

示例5: loadMetadata

 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE);
     $metadata->setCollection('cms_users');
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id'));
     $metadata->mapField(array('fieldName' => 'name', 'name' => 'username', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'mysqlProfileId', 'type' => 'integer'));
     $metadata->mapOneReference(array('fieldName' => 'address', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Address', 'cascade' => array(0 => 'remove')));
     $metadata->mapManyReference(array('fieldName' => 'phonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber')));
     $metadata->mapManyReference(array('fieldName' => 'groups', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach')));
     $metadata->mapManyEmbedded(array('fieldName' => 'otherPhonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber')));
     $metadata->addIndex(array('username' => 'desc'), array('unique' => true));
     $metadata->addIndex(array('email' => 'desc'), array('unique' => true, 'dropDups' => true));
     $metadata->addIndex(array('mysqlProfileId' => 'desc'), array('unique' => true, 'dropDups' => true));
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:19,代码来源:AbstractMappingDriverTest.php

示例6: addFieldMapping

 private function addFieldMapping(ClassMetadata $class, $mapping)
 {
     $keys = null;
     $name = isset($mapping['name']) ? $mapping['name'] : $mapping['fieldName'];
     if (isset($mapping['index'])) {
         $keys = array(
             $name => isset($mapping['index']['order']) ? $mapping['index']['order'] : 'asc'
         );
     }
     if (isset($mapping['unique'])) {
         $keys = array(
             $name => isset($mapping['unique']['order']) ? $mapping['unique']['order'] : 'asc'
         );
     }
     if ($keys !== null) {
         $options = array();
         if (isset($mapping['index'])) {
             $options = $mapping['index'];
         } elseif (isset($mapping['unique'])) {
             $options = $mapping['unique'];
             $options['unique'] = true;
         }
         $class->addIndex($keys, $options);
     }
     $class->mapField($mapping);
 }
开发者ID:royra,项目名称:mongodb-odm,代码行数:26,代码来源:YamlDriver.php

示例7: addFieldMapping

 private function addFieldMapping(ClassMetadata $class, $mapping)
 {
     $keys = null;
     $name = isset($mapping['name']) ? $mapping['name'] : $mapping['fieldName'];
     if (isset($mapping['type']) && $mapping['type'] === 'collection') {
         $mapping['strategy'] = isset($mapping['strategy']) ? $mapping['strategy'] : 'pushAll';
     }
     if (isset($mapping['index'])) {
         $keys = array($name => isset($mapping['order']) ? $mapping['order'] : 'asc');
     }
     if (isset($mapping['unique'])) {
         $keys = array($name => isset($mapping['order']) ? $mapping['order'] : 'asc');
     }
     if ($keys !== null) {
         $options = array();
         if (isset($mapping['index-name'])) {
             $options['name'] = (string) $mapping['index-name'];
         }
         if (isset($mapping['drop-dups'])) {
             $options['dropDups'] = (bool) $mapping['drop-dups'];
         }
         if (isset($mapping['background'])) {
             $options['background'] = (bool) $mapping['background'];
         }
         if (isset($mapping['safe'])) {
             $options['safe'] = (bool) $mapping['safe'];
         }
         if (isset($mapping['unique'])) {
             $options['unique'] = (bool) $mapping['unique'];
         }
         $class->addIndex($keys, $options);
     }
     $class->mapField($mapping);
 }
开发者ID:hirocaster,项目名称:mongodb-odm,代码行数:34,代码来源:XmlDriver.php

示例8: testDuplicateFieldAndAssocationMapping2

 public function testDuplicateFieldAndAssocationMapping2()
 {
     $cm = new ClassMetadata('Documents\\CmsUser');
     $cm->mapOneEmbedded(array('fieldName' => 'name', 'targetDocument' => 'CmsUser'));
     $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name', 'type' => 'string'));
     $this->assertEquals('string', $cm->fieldMappings['name']['type']);
 }
开发者ID:im286er,项目名称:ent,代码行数:7,代码来源:ClassMetadataTest.php

示例9: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $xmlRoot = $this->getElement($className);
     if (!$xmlRoot) {
         return;
     }
     if ($xmlRoot->getName() == 'document') {
         if (isset($xmlRoot['repository-class'])) {
             $class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
         }
     } elseif ($xmlRoot->getName() == 'mapped-superclass') {
         $class->isMappedSuperclass = true;
     } elseif ($xmlRoot->getName() == 'embedded-document') {
         $class->isEmbeddedDocument = true;
     }
     if (isset($xmlRoot['db'])) {
         $class->setDB((string) $xmlRoot['db']);
     }
     if (isset($xmlRoot['collection'])) {
         $class->setCollection((string) $xmlRoot['collection']);
     }
     if (isset($xmlRoot['indexes'])) {
         foreach ($xmlRoot['indexes'] as $index) {
             $class->addIndex((array) $index['keys'], (array) $index['options']);
         }
     }
     if (isset($xmlRoot['customId']) && (string) $xmlRoot['customId'] === true) {
         $class->setAllowCustomId(true);
     }
     if (isset($xmlRoot['inheritance-type'])) {
         $inheritanceType = (string) $xmlRoot['inheritance-type'];
         $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
     }
     if (isset($xmlRoot->{'discriminator-field'})) {
         $discrField = $xmlRoot->{'discriminator-field'};
         $class->setDiscriminatorField(array('name' => (string) $discrField['name'], 'fieldName' => (string) $discrField['fieldName']));
     }
     if (isset($xmlRoot->{'discriminator-map'})) {
         $map = array();
         foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
             $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
         }
         $class->setDiscriminatorMap($map);
     }
     if (isset($xmlRoot->inheritance['type'])) {
         $class->Yp = $xmlRoot['inheritance'];
     }
     if (isset($xmlRoot->{'change-tracking-policy'})) {
         $class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
     }
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $field) {
             $mapping = array();
             $attributes = $field->attributes();
             foreach ($attributes as $key => $value) {
                 $mapping[$key] = (string) $value;
                 $booleanAttributes = array('id', 'reference', 'embed');
                 if (in_array($key, $booleanAttributes)) {
                     $mapping[$key] = 'true' === $mapping[$key] ? true : false;
                 }
             }
             $class->mapField($mapping);
         }
     }
     if (isset($xmlRoot->{'embed-one'})) {
         foreach ($xmlRoot->{'embed-one'} as $embed) {
             $mapping = $this->getMappingFromEmbed($embed, 'one');
             $class->mapField($mapping);
         }
     }
     if (isset($xmlRoot->{'embed-many'})) {
         foreach ($xmlRoot->{'embed-many'} as $embed) {
             $mapping = $this->getMappingFromEmbed($embed, 'many');
             $class->mapField($mapping);
         }
     }
     if (isset($xmlRoot->{'reference-many'})) {
         foreach ($xmlRoot->{'reference-many'} as $reference) {
             $mapping = $this->getMappingFromReference($reference, 'many');
             $class->mapField($mapping);
         }
     }
     if (isset($xmlRoot->{'reference-one'})) {
         foreach ($xmlRoot->{'reference-one'} as $reference) {
             $mapping = $this->getMappingFromReference($reference, 'one');
             $class->mapField($mapping);
         }
     }
     if (isset($xmlRoot->{'lifecycle-callbacks'})) {
         foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
             $class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\MongoDB\\ODMEvents::' . (string) $lifecycleCallback['type']));
         }
     }
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:97,代码来源:XmlDriver.php

示例10: mapTranslation

 /**
  * Add mapping data to a translation entity
  *
  * @param ClassMetadata $metadata
  */
 private function mapTranslation(ClassMetadata $metadata)
 {
     // In the case A -> B -> TranslationInterface, B might not have mapping defined as it
     // is probably defined in A, so in that case, we just return;
     if (!isset($this->mappings[$metadata->name])) {
         return;
     }
     $config = $this->mappings[$metadata->name];
     $mapping = $config['translation']['mapping'];
     $metadata->isEmbeddedDocument = true;
     $metadata->isMappedSuperclass = false;
     $metadata->setIdentifier(null);
     // Map locale field.
     if (!$metadata->hasField($mapping['translation']['locale'])) {
         $metadata->mapField(array('fieldName' => $mapping['translation']['locale'], 'type' => 'string'));
     }
     // Map unique index.
     $keys = array($mapping['translation']['translatable'] => 1, $mapping['translation']['locale'] => 1);
     if (!$this->hasUniqueIndex($metadata, $keys)) {
         $metadata->addIndex($keys, array('unique' => true));
     }
 }
开发者ID:Silwereth,项目名称:Sylius,代码行数:27,代码来源:ODMTranslatableListener.php

示例11: _addInheritedFields

 /**
  * Adds inherited fields to the subclass mapping.
  *
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $subClass
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $parentClass
  */
 private function _addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass)
 {
     foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
         if (!isset($mapping['inherited'])) {
             $mapping['inherited'] = $parentClass->name;
         }
         if (!isset($mapping['declared'])) {
             $mapping['declared'] = $parentClass->name;
         }
         $subClass->mapField($mapping);
     }
     foreach ($parentClass->reflFields as $name => $field) {
         $subClass->reflFields[$name] = $field;
     }
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:21,代码来源:ClassMetadataFactory.php

示例12: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $reflClass = $class->getReflectionClass();
     $classAnnotations = $this->_reader->getClassAnnotations($reflClass);
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'])) {
         $documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'];
         if ($documentAnnot->db) {
             $class->setDB($documentAnnot->db);
         }
         if ($documentAnnot->collection) {
             $class->setCollection($documentAnnot->collection);
         }
         if ($documentAnnot->repositoryClass) {
             $class->setCustomRepositoryClass($documentAnnot->repositoryClass);
         }
         if ($documentAnnot->indexes) {
             foreach ($documentAnnot->indexes as $index) {
                 $class->addIndex($index->keys, $index->options);
             }
         }
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'])) {
             $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'];
             $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
         }
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'])) {
             $discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'];
             $class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
         }
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'])) {
             $discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'];
             $class->setDiscriminatorMap($discrMapAnnot->value);
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\MappedSuperclass'])) {
             $class->isMappedSuperclass = true;
         } else {
             if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\EmbeddedDocument'])) {
                 $class->isEmbeddedDocument = true;
             }
         }
     }
     foreach ($reflClass->getProperties() as $property) {
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         $types = array('Id', 'Increment', 'File', 'Field', 'String', 'Boolean', 'Int', 'Float', 'Date', 'Key', 'Bin', 'BinFunc', 'BinUUID', 'BinMD5', 'BinCustom', 'EmbedOne', 'EmbedMany', 'ReferenceOne', 'ReferenceMany', 'Timestamp', 'Hash', 'Collection');
         foreach ($types as $type) {
             if ($fieldAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\' . $type)) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $class->mapField($mapping);
                 break;
             }
         }
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\HasLifecycleCallbacks'])) {
         foreach ($reflClass->getMethods() as $method) {
             if ($method->isPublic()) {
                 $annotations = $this->_reader->getMethodAnnotations($method);
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PrePersist'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::prePersist);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostPersist'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postPersist);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PreUpdate'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::preUpdate);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostUpdate'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postUpdate);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PreRemove'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::preRemove);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostRemove'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postRemove);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostLoad'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\Events::postLoad);
                 }
             }
         }
     }
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:85,代码来源:AnnotationDriver.php

示例13: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $reflClass = $class->getReflectionClass();
     $classAnnotations = $this->_reader->getClassAnnotations($reflClass);
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'])) {
         $documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Document'];
         if ($documentAnnot->db) {
             $class->setDB($documentAnnot->db);
         }
         if ($documentAnnot->collection) {
             $class->setCollection($documentAnnot->collection);
         }
         if ($documentAnnot->repositoryClass) {
             $class->setCustomRepositoryClass($documentAnnot->repositoryClass);
         }
         if ($documentAnnot->indexes) {
             foreach ($documentAnnot->indexes as $index) {
                 $class->addIndex($index->keys, $index->options);
             }
         }
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'])) {
             $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\InheritanceType'];
             $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
         }
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'])) {
             $discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorField'];
             $class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
         }
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'])) {
             $discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\DiscriminatorMap'];
             $class->setDiscriminatorMap($discrMapAnnot->value);
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\MappedSuperclass'])) {
             $class->isMappedSuperclass = true;
         } else {
             if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\EmbeddedDocument'])) {
                 $class->isEmbeddedDocument = true;
             }
         }
     }
     $methods = $reflClass->getMethods();
     foreach ($reflClass->getProperties() as $property) {
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         if ($alsoLoad = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\AlsoLoad')) {
             $mapping['alsoLoadFields'] = (array) $alsoLoad->value;
         }
         if ($notSaved = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\NotSaved')) {
             $mapping['notSaved'] = true;
         }
         foreach ($this->_reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Field) {
                 if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Id && $fieldAnnot->custom) {
                     $fieldAnnot->type = 'custom_id';
                     $class->setAllowCustomId(true);
                 }
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $class->mapField($mapping);
             }
         }
         $types = array('Embed', 'Reference');
         foreach ($types as $type) {
             if ($fieldAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\' . $type)) {
                 // This is a blatant hack to see if the defined default
                 // value is an array so we can make the embed/reference many
                 // instead of one. This won't be necessary once the ReflectionProperty
                 // class has a getDefaultValue() method: http://bugs.php.net/bug.php?id=41670
                 $property->setAccessible(true);
                 $default = $property->getValue(new $class->name());
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 if (is_array($default)) {
                     $mapping['type'] = 'many';
                 } else {
                     $mapping['type'] = 'one';
                 }
                 $class->mapField($mapping);
             }
         }
     }
     foreach ($methods as $method) {
         if ($method->isPublic()) {
             if ($alsoLoad = $this->_reader->getMethodAnnotation($method, 'Doctrine\\ODM\\MongoDB\\Mapping\\AlsoLoad')) {
                 $class->fieldMappings[$mapping['fieldName']]['alsoLoadMethods'][] = array('name' => (array) $alsoLoad->value, 'method' => $method->getName());
             }
         }
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\HasLifecycleCallbacks'])) {
         foreach ($methods as $method) {
             if ($method->isPublic()) {
                 $annotations = $this->_reader->getMethodAnnotations($method);
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PrePersist'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\ODMEvents::prePersist);
                 }
                 if (isset($annotations['Doctrine\\ODM\\MongoDB\\Mapping\\PostPersist'])) {
                     $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\MongoDB\ODMEvents::postPersist);
                 }
//.........这里部分代码省略.........
开发者ID:klaasn,项目名称:symfony-sandbox,代码行数:101,代码来源:AnnotationDriver.php

示例14: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $element = $this->getElement($className);
     if (!$element) {
         return;
     }
     $element['type'] = isset($element['type']) ? $element['type'] : 'document';
     if (isset($element['db'])) {
         $class->setDB($element['db']);
     }
     if (isset($element['collection'])) {
         $class->setCollection($element['collection']);
     }
     if ($element['type'] == 'document') {
         if (isset($element['repositoryClass'])) {
             $class->setCustomRepositoryClass($element['repositoryClass']);
         }
     } elseif ($element['type'] === 'mappedSuperclass') {
         $class->isMappedSuperclass = true;
     } elseif ($element['type'] === 'embeddedDocument') {
         $class->isEmbeddedDocument = true;
     }
     if (isset($element['indexes'])) {
         foreach ($element['indexes'] as $index) {
             $class->addIndex($index['keys'], $index['options']);
         }
     }
     if (isset($element['inheritanceType'])) {
         $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
     }
     if (isset($element['discriminatorColumn'])) {
         $discrColumn = $element['discriminatorColumn'];
         $class->setDiscriminatorColumn(array('name' => $discrColumn['name'], 'fieldName' => $discrColumn['fieldName']));
     }
     if (isset($element['discriminatorMap'])) {
         $class->setDiscriminatorMap($element['discriminatorMap']);
     }
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $fieldName => $mapping) {
             if (!isset($mapping['fieldName'])) {
                 $mapping['fieldName'] = $fieldName;
             }
             $class->mapField($mapping);
         }
     }
     if (isset($element['embedOne'])) {
         foreach ($element['embedOne'] as $fieldName => $embed) {
             $mapping = $this->_getMappingFromEmbed($fieldName, $embed, 'one');
             $class->mapField($mapping);
         }
     }
     if (isset($element['embedMany'])) {
         foreach ($element['embedMany'] as $fieldName => $embed) {
             $mapping = $this->_getMappingFromEmbed($fieldName, $embed, 'many');
             $class->mapField($mapping);
         }
     }
     if (isset($element['referenceOne'])) {
         foreach ($element['referenceOne'] as $fieldName => $reference) {
             $mapping = $this->_getMappingFromReference($fieldName, $reference, 'one');
             $class->mapField($mapping);
         }
     }
     if (isset($element['referenceMany'])) {
         foreach ($element['referenceMany'] as $fieldName => $reference) {
             $mapping = $this->_getMappingFromReference($fieldName, $reference, 'many');
             $class->mapField($mapping);
         }
     }
     if (isset($element['lifecycleCallbacks'])) {
         foreach ($element['lifecycleCallbacks'] as $type => $methods) {
             foreach ($methods as $method) {
                 $class->addLifecycleCallback($method, constant('Doctrine\\ORM\\Events::' . $type));
             }
         }
     }
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:80,代码来源:YamlDriver.php

示例15: testMapNotExistingFieldThrowsException

 /**
  * @expectedException \ReflectionException
  */
 public function testMapNotExistingFieldThrowsException()
 {
     $cm = new ClassMetadata('Documents\\CmsUser');
     $cm->mapField(array('fieldName' => 'namee', 'columnName' => 'name', 'type' => 'string'));
 }
开发者ID:WillSkates,项目名称:mongodb-odm,代码行数:8,代码来源:ClassMetadataTest.php


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