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


PHP ClassMetadata::setIdGeneratorType方法代码示例

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


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

示例1: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockPlatform = new DatabasePlatformMock();
     $mockDriver = new MetadataDriverMock();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     // 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' => 'Other', 'mappedBy' => 'this'));
     // and an id generator type
     $cm1->setIdGeneratorType('auto');
     // SUT
     $cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform);
     $cmf->setMetadataForClass('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals('none', $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(1, count($cm1->associationMappings));
     $this->assertEquals('auto', $cm1->generatorType);
     // Go
     $cm1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals('sequence', $cm1->generatorType);
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:31,代码来源:ClassMetadataFactoryTest.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: 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

示例4: testSequenceGenerator

    /**
     * @group DDC-3428
     */
    public function testSequenceGenerator()
    {
        $exporter = new XmlExporter();
        $metadata = new ClassMetadata('entityTest');
        $metadata->mapField(array("fieldName" => 'id', "type" => 'integer', "columnName" => 'id', "id" => true));
        $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
        $metadata->setSequenceGeneratorDefinition(array('sequenceName' => 'seq_entity_test_id', 'allocationSize' => 5, 'initialValue' => 1));
        $expectedFileContent = <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
    xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
  <entity name="entityTest">
    <id name="id" type="integer" column="id">
      <generator strategy="SEQUENCE"/>
      <sequence-generator sequence-name="seq_entity_test_id" allocation-size="5" initial-value="1"/>
    </id>
  </entity>
</doctrine-mapping>
XML;
        $this->assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
    }
开发者ID:selimcr,项目名称:servigases,代码行数:27,代码来源:XmlClassMetadataExporterTest.php

示例5: mapId

 /**
  * Kept for BC-compatibility purposes : people expect this lib to map ids for
  * translations.
  *
  * @deprecated It should be removed because it probably does not work with
  *             every doctrine version.
  *
  * @see https://github.com/doctrine/doctrine2/blob/0bff6aadbc9f3fd8167a320d9f4f6cf269382da0/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L508
  */
 private function mapId(ClassMetadata $class, EntityManager $em)
 {
     $platform = $em->getConnection()->getDatabasePlatform();
     if (!$class->hasField('id')) {
         $builder = new ClassMetadataBuilder($class);
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         /// START DOCTRINE CODE
         $idGenType = $class->generatorType;
         if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
             if ($platform->prefersSequences()) {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
             } else {
                 if ($platform->prefersIdentityColumns()) {
                     $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
                 } else {
                     $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
                 }
             }
         }
         // Create & assign an appropriate ID generator instance
         switch ($class->generatorType) {
             case ClassMetadata::GENERATOR_TYPE_IDENTITY:
                 // For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to
                 // <table>_<column>_seq in PostgreSQL for SERIAL columns.
                 // Not pretty but necessary and the simplest solution that currently works.
                 $sequenceName = null;
                 $fieldName = $class->identifier ? $class->getSingleIdentifierFieldName() : null;
                 if ($platform instanceof Platforms\PostgreSQLPlatform) {
                     $columnName = $class->getSingleIdentifierColumnName();
                     $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
                     $sequenceName = $class->getTableName() . '_' . $columnName . '_seq';
                     $definition = array('sequenceName' => $platform->fixSchemaElementName($sequenceName));
                     if ($quoted) {
                         $definition['quoted'] = true;
                     }
                     $sequenceName = $em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $platform);
                 }
                 $generator = $fieldName && $class->fieldMappings[$fieldName]['type'] === 'bigint' ? new BigIntegerIdentityGenerator($sequenceName) : new IdentityGenerator($sequenceName);
                 $class->setIdGenerator($generator);
                 break;
             case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
                 // If there is no sequence definition yet, create a default definition
                 $definition = $class->sequenceGeneratorDefinition;
                 if (!$definition) {
                     $fieldName = $class->getSingleIdentifierFieldName();
                     $columnName = $class->getSingleIdentifierColumnName();
                     $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
                     $sequenceName = $class->getTableName() . '_' . $columnName . '_seq';
                     $definition = array('sequenceName' => $platform->fixSchemaElementName($sequenceName), 'allocationSize' => 1, 'initialValue' => 1);
                     if ($quoted) {
                         $definition['quoted'] = true;
                     }
                     $class->setSequenceGeneratorDefinition($definition);
                 }
                 $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $platform), $definition['allocationSize']);
                 $class->setIdGenerator($sequenceGenerator);
                 break;
             case ClassMetadata::GENERATOR_TYPE_NONE:
                 $class->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
                 break;
             case ClassMetadata::GENERATOR_TYPE_UUID:
                 $class->setIdGenerator(new \Doctrine\ORM\Id\UuidGenerator());
                 break;
             case ClassMetadata::GENERATOR_TYPE_TABLE:
                 throw new ORMException("TableGenerator not yet implemented.");
                 break;
             case ClassMetadata::GENERATOR_TYPE_CUSTOM:
                 $definition = $class->customGeneratorDefinition;
                 if (!class_exists($definition['class'])) {
                     throw new ORMException("Can't instantiate custom generator : " . $definition['class']);
                 }
                 $class->setIdGenerator(new $definition['class']());
                 break;
             default:
                 throw new ORMException("Unknown generator type: " . $class->generatorType);
         }
         /// END DOCTRINE COPY / PASTED code
     }
 }
开发者ID:jdachtera,项目名称:DoctrineBehaviors,代码行数:88,代码来源:TranslatableSubscriber.php

示例6: _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

示例7: _completeIdGeneratorMapping

 /**
  * Completes the ID generator mapping. If "auto" is specified we choose the generator
  * most appropriate for the targeted database platform.
  *
  * @param Doctrine\ORM\Mapping\ClassMetadata $class
  */
 private function _completeIdGeneratorMapping(ClassMetadata $class)
 {
     $idGenType = $class->generatorType;
     if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
         if ($this->_targetPlatform->prefersSequences()) {
             $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
         } else {
             if ($this->_targetPlatform->prefersIdentityColumns()) {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
             } else {
                 $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
             }
         }
     }
     // Create & assign an appropriate ID generator instance
     switch ($class->generatorType) {
         case ClassMetadata::GENERATOR_TYPE_IDENTITY:
             $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
             // If there is no sequence definition yet, create a default definition
             $definition = $class->sequenceGeneratorDefinition;
             if (!$definition) {
                 $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq';
                 $definition['sequenceName'] = $this->_targetPlatform->fixSchemaElementName($sequenceName);
                 $definition['allocationSize'] = 10;
                 $definition['initialValue'] = 1;
                 $class->setSequenceGeneratorDefinition($definition);
             }
             $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($definition['sequenceName'], $definition['allocationSize']);
             $class->setIdGenerator($sequenceGenerator);
             break;
         case ClassMetadata::GENERATOR_TYPE_NONE:
             $class->setIdGenerator(new \Doctrine\ORM\Id\Assigned());
             break;
         case ClassMetadata::GENERATOR_TYPE_TABLE:
             throw new ORMException("TableGenerator not yet implemented.");
             break;
         default:
             throw new ORMException("Unknown generator type: " . $class->generatorType);
     }
 }
开发者ID:andreia,项目名称:doctrine,代码行数:48,代码来源:ClassMetadataFactory.php

示例8: 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::setIdGeneratorType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。