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


PHP ClassMetadata::setPrimaryTable方法代码示例

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


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

示例1: loadMetadata

 /**
  * Metadata definition for static_php metadata driver.
  * @param  ClassMetadata $metadata
  * @return void
  */
 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setPrimaryTable(['name' => 'password_resets']);
     $metadata->mapField(['id' => true, 'fieldName' => 'email', 'type' => 'string']);
     $metadata->mapField(['fieldName' => 'token', 'type' => 'string']);
     $metadata->mapField(['columnName' => 'created_at', 'fieldName' => 'createdAt', 'type' => 'datetime', 'nullable' => false]);
 }
开发者ID:spohess,项目名称:orm,代码行数:12,代码来源:PasswordReminder.php

示例2: prepare

 private function prepare()
 {
     $cmf = $this->em->getMetadataFactory();
     $metadata = new ClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable');
     $id = array();
     $id['fieldName'] = 'id';
     $id['type'] = 'integer';
     $id['nullable'] = false;
     $id['columnName'] = 'id';
     $id['id'] = true;
     $metadata->mapField($id);
     $created = array();
     $created['fieldName'] = 'created';
     $created['type'] = 'datetime';
     $created['nullable'] = false;
     $created['columnName'] = 'created';
     $metadata->mapField($created);
     $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator(null));
     $metadata->setPrimaryTable(array('name' => 'temp_test'));
     $cmf->setMetadataFor('Mapping\\Fixture\\Unmapped\\Timestampable', $metadata);
     // trigger loadClassMetadata event
     $evm = $this->em->getEventManager();
     $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($metadata, $this->em);
     $evm->dispatchEvent(\Doctrine\ORM\Events::loadClassMetadata, $eventArgs);
     if (Version::compare('2.3.0-dev') <= 0) {
         $metadata->wakeupReflection($cmf->getReflectionService());
     }
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($this->em->getClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable')));
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:32,代码来源:ForcedMetadataTest.php

示例3: loadMetadataForClass

 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $entity = $this->_entities[$className];
     if (isset($entity['repositoryClass']) && $entity['repositoryClass']) {
         $metadata->setCustomRepositoryClass($entity['repositoryClass']);
     }
     if (isset($entity['table'])) {
         $metadata->setPrimaryTable($entity['table']);
     }
     if (isset($entity['inheritanceType']) && $entity['inheritanceType']) {
         $metadata->setInheritanceType($entity['inheritanceType']);
     }
     if (isset($entity['discriminatorColumn'])) {
         $metadata->setDiscriminatorColumn($entity['discriminatorColumn']);
     }
     if (isset($entity['discriminatorValue']) && $entity['discriminatorValue']) {
         $metadata->setDiscriminatorValue($entity['discriminatorValue']);
     }
     if (isset($entity['subClasses']) && $entity['subClasses']) {
         $metadata->setSubclasses((array) $entity['subClasses']);
     }
     $relationTypes = array('OneToOne', 'OneToMany', 'ManyToOne', 'ManyToMany');
     foreach ($entity['properties'] as $name => $property) {
         $mapping = array();
         $mapping['fieldName'] = $name;
         $joinColumns = array();
         if (isset($property['joinColumn']) && $property['joinColumn']) {
             $joinColumns[] = $property['joinColumn'];
         } else {
             if (isset($property['joinColumns']) && $property['joinColumns']) {
                 $joinColumns = $property['joinColumns'];
             }
         }
         $type = $property['type'];
         $mapping = array_merge($mapping, $property);
         if (in_array($type, $relationTypes)) {
             unset($property['type']);
             switch ($type) {
                 case 'ManyToOne':
                 case 'OneToOne':
                     $mapping['joinColumns'] = $joinColumns;
                     break;
                 case 'ManyToMany':
                     $joinTable = array();
                     if (isset($property['joinTable'])) {
                         $joinTable = $property['joinTable'];
                     }
                     $mapping['joinTable'] = $joinTable;
                     break;
                 case 'OneToMany':
                 default:
                     break;
             }
             $func = 'map' . $type;
             $metadata->{$func}($mapping);
         } else {
             $metadata->mapField($mapping);
         }
     }
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:60,代码来源:YamlDriver.php

示例4: testGetTableName

 public function testGetTableName()
 {
     $cm = $this->createClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->setPrimaryTable(array('name' => '`cms_user`'));
     $this->assertEquals('"cms_user"', $this->strategy->getTableName($cm, $this->platform));
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm->setPrimaryTable(array('name' => 'cms_user'));
     $this->assertEquals('cms_user', $this->strategy->getTableName($cm, $this->platform));
 }
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:10,代码来源:QuoteStrategyTest.php

示例5: testPrefixManyToMany

 public function testPrefixManyToMany()
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $subscriber = new TablePrefixSubscriber('yo_');
     $metaClass = new ClassMetadata('Wallabag\\UserBundle\\Entity\\Entry');
     $metaClass->setPrimaryTable(['name' => 'entry']);
     $metaClass->mapManyToMany(['fieldName' => 'tags', 'joinTable' => ['name' => null, 'schema' => null], 'targetEntity' => 'Tag', 'mappedBy' => null, 'inversedBy' => 'entries', 'cascade' => ['persist'], 'indexBy' => null, 'orphanRemoval' => false, 'fetch' => 2]);
     $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em);
     $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName());
     $subscriber->loadClassMetadata($metaDataEvent);
     $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName());
     $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']);
     $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform()));
 }
开发者ID:jjanvier,项目名称:wallabag,代码行数:14,代码来源:TablePrefixSubscriberTest.php

示例6: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:42,代码来源:ClassMetadataFactoryTest.php

示例7: testDefaultTableName

 public function testDefaultTableName()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     // When table's name is not given
     $primaryTable = array();
     $cm->setPrimaryTable($primaryTable);
     $this->assertEquals('CmsUser', $cm->getTableName());
     $this->assertEquals('CmsUser', $cm->table['name']);
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress');
     // When joinTable's name is not given
     $cm->mapManyToMany(array('fieldName' => 'user', 'targetEntity' => 'CmsUser', 'inversedBy' => 'users', 'joinTable' => array('joinColumns' => array(array('referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('referencedColumnName' => 'id')))));
     $this->assertEquals('cmsaddress_cmsuser', $cm->associationMappings['user']['joinTable']['name']);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:13,代码来源:ClassMetadataTest.php

示例8: _createValidClassMetadata

 /**
  * @param string $class
  * @return ClassMetadata
  */
 protected function _createValidClassMetadata()
 {
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     return $cm1;
 }
开发者ID:naumangcu,项目名称:doctrine2,代码行数:23,代码来源:ClassMetadataFactoryTest.php

示例9: setTable

 /**
  * Set the table name
  *
  * @param string $name
  * @return ClassMetadataBuilder
  */
 public function setTable($name)
 {
     $this->cm->setPrimaryTable(array('name' => $name));
     return $this;
 }
开发者ID:ramonornela,项目名称:doctrine2,代码行数:11,代码来源:ClassMetadataBuilder.php

示例10: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $annotClass = new \Addendum\ReflectionAnnotatedClass($className);
     // Evaluate DoctrineEntity annotation
     if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) {
         throw DoctrineException::updateMe("{$className} is no entity.");
     }
     $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
     // Evaluate DoctrineTable annotation
     if ($tableAnnot = $annotClass->getAnnotation('DoctrineTable')) {
         $metadata->setPrimaryTable(array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema, 'catalog' => $tableAnnot->catalog));
     }
     // Evaluate DoctrineInheritanceType annotation
     if ($inheritanceTypeAnnot = $annotClass->getAnnotation('DoctrineInheritanceType')) {
         $metadata->setInheritanceType($inheritanceTypeAnnot->value);
     }
     // Evaluate DoctrineDiscriminatorColumn annotation
     if ($discrColumnAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorColumn')) {
         $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length));
     }
     // Evaluate DoctrineDiscriminatorMap annotation
     if ($discrValueAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorValue')) {
         $metadata->setDiscriminatorValue($discrValueAnnot->value);
     }
     // Evaluate DoctrineSubClasses annotation
     if ($subClassesAnnot = $annotClass->getAnnotation('DoctrineSubClasses')) {
         $metadata->setSubclasses($subClassesAnnot->value);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if ($changeTrackingAnnot = $annotClass->getAnnotation('DoctrineChangeTrackingPolicy')) {
         $metadata->setChangeTrackingPolicy($changeTrackingAnnot->value);
     }
     // Evaluate annotations on properties/fields
     foreach ($annotClass->getProperties() as $property) {
         if ($metadata->hasField($property->getName())) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for DoctrineJoinColummn/DoctrineJoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $property->getAnnotation('DoctrineJoinColumn')) {
             $joinColumns[] = array('name' => $joinColumnAnnot->name, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'unique' => $joinColumnAnnot->unique, 'nullable' => $joinColumnAnnot->nullable, 'onDelete' => $joinColumnAnnot->onDelete, 'onUpdate' => $joinColumnAnnot->onUpdate);
         } else {
             if ($joinColumnsAnnot = $property->getAnnotation('DoctrineJoinColumns')) {
                 $joinColumns = $joinColumnsAnnot->value;
             }
         }
         // Field can only be annotated with one of: DoctrineColumn,
         // DoctrineOneToOne, DoctrineOneToMany, DoctrineManyToOne, DoctrineManyToMany
         if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) {
             if ($columnAnnot->type == null) {
                 throw DoctrineException::updateMe("Missing type on property " . $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['nullable'] = $columnAnnot->nullable;
             if ($idAnnot = $property->getAnnotation('DoctrineId')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $property->getAnnotation('DoctrineGeneratedValue')) {
                 $metadata->setIdGeneratorType($generatedValueAnnot->strategy);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $property->getAnnotation('DoctrineSequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $property->getAnnotation('DoctrineTableGenerator')) {
                     throw new DoctrineException("DoctrineTableGenerator not yet implemented.");
                 }
             }
         } else {
             if ($oneToOneAnnot = $property->getAnnotation('DoctrineOneToOne')) {
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $property->getAnnotation('DoctrineOneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $property->getAnnotation('DoctrineManyToOne')) {
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $property->getAnnotation('DoctrineManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $property->getAnnotation('DoctrineJoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema, 'catalog' => $joinTableAnnot->catalog, 'joinColumns' => $joinTableAnnot->joinColumns, 'inverseJoinColumns' => $joinTableAnnot->inverseJoinColumns);
                             }
//.........这里部分代码省略.........
开发者ID:jackbravo,项目名称:doctrine,代码行数:101,代码来源:AnnotationDriver.php


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