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


PHP ClassMetadataInfo::setSequenceGeneratorDefinition方法代码示例

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


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

示例1: testPrefixAddedToSequence

 public function testPrefixAddedToSequence()
 {
     $this->metadata->setSequenceGeneratorDefinition(['sequenceName' => 'bar']);
     $this->metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
     $tablePrefix = new TablePrefixListener('someprefix_');
     $tablePrefix->loadClassMetadata($this->args);
     $this->assertEquals('someprefix_foo', $this->metadata->getTableName());
 }
开发者ID:jee7,项目名称:orm,代码行数:8,代码来源:TablePrefixTest.php

示例2: loadMetadataForClass


//.........这里部分代码省略.........
                 $mapping['columnDefinition'] = (string) $fieldMapping['column-definition'];
             }
             if (isset($fieldMapping->options)) {
                 $mapping['options'] = $this->_parseOptions($fieldMapping->options->children());
             }
             $metadata->mapField($mapping);
         }
     }
     // Evaluate <id ...> mappings
     $associationIds = array();
     foreach ($xmlRoot->id as $idElement) {
         if ((bool) $idElement['association-key'] == true) {
             $associationIds[(string) $idElement['name']] = true;
             continue;
         }
         $mapping = array('id' => true, 'fieldName' => (string) $idElement['name']);
         if (isset($idElement['type'])) {
             $mapping['type'] = (string) $idElement['type'];
         }
         if (isset($idElement['column'])) {
             $mapping['columnName'] = (string) $idElement['column'];
         }
         if (isset($idElement['column-definition'])) {
             $mapping['columnDefinition'] = (string) $idElement['column-definition'];
         }
         $metadata->mapField($mapping);
         if (isset($idElement->generator)) {
             $strategy = isset($idElement->generator['strategy']) ? (string) $idElement->generator['strategy'] : 'AUTO';
             $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $strategy));
         }
         // Check for SequenceGenerator/TableGenerator definition
         if (isset($idElement->{'sequence-generator'})) {
             $seqGenerator = $idElement->{'sequence-generator'};
             $metadata->setSequenceGeneratorDefinition(array('sequenceName' => (string) $seqGenerator['sequence-name'], 'allocationSize' => (string) $seqGenerator['allocation-size'], 'initialValue' => (string) $seqGenerator['initial-value']));
         } else {
             if (isset($idElement->{'table-generator'})) {
                 throw MappingException::tableIdGeneratorNotImplemented($className);
             }
         }
     }
     // Evaluate <one-to-one ...> mappings
     if (isset($xmlRoot->{'one-to-one'})) {
         foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) {
             $mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']);
             if (isset($associationIds[$mapping['fieldName']])) {
                 $mapping['id'] = true;
             }
             if (isset($oneToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToOneElement['fetch']);
             }
             if (isset($oneToOneElement['mapped-by'])) {
                 $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by'];
             } else {
                 if (isset($oneToOneElement['inversed-by'])) {
                     $mapping['inversedBy'] = (string) $oneToOneElement['inversed-by'];
                 }
                 $joinColumns = array();
                 if (isset($oneToOneElement->{'join-column'})) {
                     $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'});
                 } else {
                     if (isset($oneToOneElement->{'join-columns'})) {
                         foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                             $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                         }
                     }
                 }
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:67,代码来源:XmlDriver.php

示例3: loadMetadata

 public static function loadMetadata(ClassMetadataInfo $metadata)
 {
     $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
     $metadata->setPrimaryTable(array('name' => 'cms_users'));
     $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id'));
     $metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50, 'unique' => true, 'nullable' => true, 'columnName' => 'name'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string', 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL'));
     $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     $metadata->mapOneToOne(array('fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', 'cascade' => array(0 => 'remove'), 'mappedBy' => NULL, 'inversedBy' => 'user', 'joinColumns' => array(0 => array('name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')), 'orphanRemoval' => false));
     $metadata->mapOneToMany(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'mappedBy' => 'user', 'orphanRemoval' => true, 'orderBy' => array('number' => 'ASC')));
     $metadata->mapManyToMany(array('fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach'), 'mappedBy' => NULL, 'joinTable' => array('name' => 'cms_users_groups', 'joinColumns' => array(0 => array('name' => 'user_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false)), 'inverseJoinColumns' => array(0 => array('name' => 'group_id', 'referencedColumnName' => 'id', 'columnDefinition' => 'INT NULL'))), 'orderBy' => NULL));
     $metadata->table['uniqueConstraints'] = array('search_idx' => array('columns' => array('name', 'user_email')));
     $metadata->table['indexes'] = array('name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email')));
     $metadata->setSequenceGeneratorDefinition(array('sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:19,代码来源:AbstractMappingDriverTest.php

示例4: loadMetadataForClass


//.........这里部分代码省略.........
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['precision'] = $columnAnnot->precision;
             $mapping['scale'] = $columnAnnot->scale;
             $mapping['nullable'] = $columnAnnot->nullable;
             $mapping['unique'] = $columnAnnot->unique;
             if ($columnAnnot->options) {
                 $mapping['options'] = $columnAnnot->options;
             }
             if (isset($columnAnnot->name)) {
                 $mapping['columnName'] = $columnAnnot->name;
             }
             if (isset($columnAnnot->columnDefinition)) {
                 $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
             }
             if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                     $mapping['id'] = true;
                 }
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['inversedBy'] = $oneToOneAnnot->inversedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $mapping['indexBy'] = $oneToManyAnnot->indexBy;
                     $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
                     if ($orderByAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                         $mapping['orderBy'] = $orderByAnnot->value;
                     }
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:67,代码来源:AnnotationDriver.php

示例5: loadMetadataForClass


//.........这里部分代码省略.........
             } else {
                 $columns = $unique['columns'];
             }
             $metadata->table['uniqueConstraints'][$unique['name']] = array('columns' => $columns);
         }
     }
     $associationIds = array();
     if (isset($element['id'])) {
         // Evaluate identifier settings
         foreach ($element['id'] as $name => $idElement) {
             if (isset($idElement['associationKey']) && $idElement['associationKey'] == true) {
                 $associationIds[$name] = true;
                 continue;
             }
             $mapping = array('id' => true, 'fieldName' => $name);
             if (isset($idElement['type'])) {
                 $mapping['type'] = $idElement['type'];
             }
             if (isset($idElement['column'])) {
                 $mapping['columnName'] = $idElement['column'];
             }
             if (isset($idElement['length'])) {
                 $mapping['length'] = $idElement['length'];
             }
             if (isset($idElement['columnDefinition'])) {
                 $mapping['columnDefinition'] = $idElement['columnDefinition'];
             }
             $metadata->mapField($mapping);
             if (isset($idElement['generator'])) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($idElement['generator']['strategy'])));
             }
             // Check for SequenceGenerator/TableGenerator definition
             if (isset($idElement['sequenceGenerator'])) {
                 $metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']);
             } else {
                 if (isset($idElement['tableGenerator'])) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         }
     }
     // Evaluate fields
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $name => $fieldMapping) {
             $mapping = array('fieldName' => $name);
             if (isset($fieldMapping['type'])) {
                 $e = explode('(', $fieldMapping['type']);
                 $fieldMapping['type'] = $e[0];
                 $mapping['type'] = $fieldMapping['type'];
                 if (isset($e[1])) {
                     $fieldMapping['length'] = substr($e[1], 0, strlen($e[1]) - 1);
                 }
             }
             if (isset($fieldMapping['id'])) {
                 $mapping['id'] = true;
                 if (isset($fieldMapping['generator']['strategy'])) {
                     $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($fieldMapping['generator']['strategy'])));
                 }
             }
             if (isset($fieldMapping['column'])) {
                 $mapping['columnName'] = $fieldMapping['column'];
             }
             if (isset($fieldMapping['length'])) {
                 $mapping['length'] = $fieldMapping['length'];
             }
             if (isset($fieldMapping['precision'])) {
开发者ID:williamamed,项目名称:Raptor2,代码行数:67,代码来源:YamlDriver.php

示例6: testGenerateEntityWithSequenceGenerator

 /**
  * @group DDC-1784
  */
 public function testGenerateEntityWithSequenceGenerator()
 {
     $metadata = new ClassMetadataInfo($this->_namespace . '\\DDC1784Entity');
     $metadata->namespace = $this->_namespace;
     $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
     $metadata->setSequenceGeneratorDefinition(array('sequenceName' => 'DDC1784_ID_SEQ', 'allocationSize' => 1, 'initialValue' => 2));
     $this->_generator->writeEntityClass($metadata, $this->_tmpDir);
     $filename = $this->_tmpDir . DIRECTORY_SEPARATOR . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC1784Entity.php';
     $this->assertFileExists($filename);
     require_once $filename;
     $reflection = new \ReflectionProperty($metadata->name, 'id');
     $docComment = $reflection->getDocComment();
     $this->assertContains('@Id', $docComment);
     $this->assertContains('@Column(name="id", type="integer")', $docComment);
     $this->assertContains('@GeneratedValue(strategy="SEQUENCE")', $docComment);
     $this->assertContains('@SequenceGenerator(sequenceName="DDC1784_ID_SEQ", allocationSize=1, initialValue=2)', $docComment);
 }
开发者ID:selimcr,项目名称:servigases,代码行数:21,代码来源:EntityGeneratorTest.php

示例7: evaluatePropertyAnnotations


//.........这里部分代码省略.........
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapOneToMany($mapping);
         } elseif ($manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
             if ($manyToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToOneAnnotation->targetEntity;
             }
             $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             if ($manyToOneAnnotation->cascade) {
                 $mapping['cascade'] = $manyToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['inversedBy'] = $manyToOneAnnotation->inversedBy;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnotation->fetch);
             $metadata->mapManyToOne($mapping);
         } elseif ($manyToManyAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
             if ($manyToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             /** @var JoinTable $joinTableAnnotation */
             if ($joinTableAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                 $joinTable = $this->evaluateJoinTableAnnotation($joinTableAnnotation, $property, $className, $mapping);
             } else {
                 $joinColumns = array(array('name' => null, 'referencedColumnName' => null));
                 $joinTable = array('name' => $this->inferJoinTableNameFromClassAndPropertyName($className, $property->getName()), 'joinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property, self::MAPPING_MM_REGULAR), 'inverseJoinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property));
             }
             $mapping['joinTable'] = $joinTable;
             $mapping['mappedBy'] = $manyToManyAnnotation->mappedBy;
             $mapping['inversedBy'] = $manyToManyAnnotation->inversedBy;
             if ($manyToManyAnnotation->cascade) {
                 $mapping['cascade'] = $manyToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['indexBy'] = $manyToManyAnnotation->indexBy;
             $mapping['orphanRemoval'] = $manyToManyAnnotation->orphanRemoval;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapManyToMany($mapping);
         } else {
             $mapping['nullable'] = false;
             /** @var Column $columnAnnotation */
             if ($columnAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
                 $mapping = $this->addColumnToMappingArray($columnAnnotation, $mapping);
             }
             if (!isset($mapping['type'])) {
                 switch ($propertyMetaData['type']) {
                     case 'DateTime':
                         $mapping['type'] = 'datetime';
                         break;
                     case 'string':
                     case 'integer':
                     case 'boolean':
                     case 'float':
                     case 'array':
                         $mapping['type'] = $propertyMetaData['type'];
                         break;
                     default:
                         if (strpos($propertyMetaData['type'], '\\') !== false) {
                             if ($this->reflectionService->isClassAnnotatedWith($propertyMetaData['type'], \TYPO3\Flow\Annotations\ValueObject::class)) {
                                 $mapping['type'] = 'object';
                             } elseif (class_exists($propertyMetaData['type'])) {
                                 throw MappingException::missingRequiredOption($property->getName(), 'OneToOne', sprintf('The property "%s" in class "%s" has a non standard data type and doesn\'t define the type of the relation. You have to use one of these annotations: @OneToOne, @OneToMany, @ManyToOne, @ManyToMany', $property->getName(), $className));
                             }
                         } else {
                             throw MappingException::propertyTypeIsRequired($className, $property->getName());
                         }
                 }
             }
             if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id') !== null) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($generatedValueAnnotation->strategy)));
             }
             if ($this->reflectionService->isPropertyAnnotatedWith($className, $property->getName(), 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnotation->sequenceName, 'allocationSize' => $seqGeneratorAnnotation->allocationSize, 'initialValue' => $seqGeneratorAnnotation->initialValue));
             } elseif ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator') !== null) {
                 throw MappingException::tableIdGeneratorNotImplemented($className);
             } elseif ($customGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\CustomIdGenerator')) {
                 $metadata->setCustomGeneratorDefinition(array('class' => $customGeneratorAnnotation->class));
             }
         }
     }
 }
开发者ID:robertlemke,项目名称:flow-development-collection,代码行数:101,代码来源:FlowAnnotationDriver.php

示例8: convertColumn

 /**
  * @param string            $className
  * @param string            $name
  * @param string|array      $column
  * @param ClassMetadataInfo $metadata
  *
  * @return array
  *
  * @throws ToolsException
  */
 private function convertColumn($className, $name, $column, ClassMetadataInfo $metadata)
 {
     if (is_string($column)) {
         $string = $column;
         $column = array();
         $column['type'] = $string;
     }
     if (!isset($column['name'])) {
         $column['name'] = $name;
     }
     // check if a column alias was used (column_name as field_name)
     if (preg_match("/(\\w+)\\sas\\s(\\w+)/i", $column['name'], $matches)) {
         $name = $matches[1];
         $column['name'] = $name;
         $column['alias'] = $matches[2];
     }
     if (preg_match("/([a-zA-Z]+)\\(([0-9]+)\\)/", $column['type'], $matches)) {
         $column['type'] = $matches[1];
         $column['length'] = $matches[2];
     }
     $column['type'] = strtolower($column['type']);
     // check if legacy column type (1.x) needs to be mapped to a 2.0 one
     if (isset($this->legacyTypeMap[$column['type']])) {
         $column['type'] = $this->legacyTypeMap[$column['type']];
     }
     if (!Type::hasType($column['type'])) {
         throw ToolsException::couldNotMapDoctrine1Type($column['type']);
     }
     $fieldMapping = array();
     if (isset($column['primary'])) {
         $fieldMapping['id'] = true;
     }
     $fieldMapping['fieldName'] = isset($column['alias']) ? $column['alias'] : $name;
     $fieldMapping['columnName'] = $column['name'];
     $fieldMapping['type'] = $column['type'];
     if (isset($column['length'])) {
         $fieldMapping['length'] = $column['length'];
     }
     $allowed = array('precision', 'scale', 'unique', 'options', 'notnull', 'version');
     foreach ($column as $key => $value) {
         if (in_array($key, $allowed)) {
             $fieldMapping[$key] = $value;
         }
     }
     $metadata->mapField($fieldMapping);
     if (isset($column['autoincrement'])) {
         $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     } elseif (isset($column['sequence'])) {
         $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
         $definition = array('sequenceName' => is_array($column['sequence']) ? $column['sequence']['name'] : $column['sequence']);
         if (isset($column['sequence']['size'])) {
             $definition['allocationSize'] = $column['sequence']['size'];
         }
         if (isset($column['sequence']['value'])) {
             $definition['initialValue'] = $column['sequence']['value'];
         }
         $metadata->setSequenceGeneratorDefinition($definition);
     }
     return $fieldMapping;
 }
开发者ID:SylvainSimon,项目名称:Metinify,代码行数:70,代码来源:ConvertDoctrine1Schema.php

示例9: inheritIdGeneratorMapping

 /**
  * Inherits the ID generator mapping from a parent class.
  *
  * @param ClassMetadataInfo $class
  * @param ClassMetadataInfo $parent
  */
 private function inheritIdGeneratorMapping(ClassMetadataInfo $class, ClassMetadataInfo $parent)
 {
     if ($parent->isIdGeneratorSequence()) {
         $class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
     } elseif ($parent->isIdGeneratorTable()) {
         $class->tableGeneratorDefinition = $parent->tableGeneratorDefinition;
     }
     if ($parent->generatorType) {
         $class->setIdGeneratorType($parent->generatorType);
     }
     if ($parent->idGenerator) {
         $class->setIdGenerator($parent->idGenerator);
     }
 }
开发者ID:StoshSeb,项目名称:doctrine2,代码行数:20,代码来源:ClassMetadataFactory.php

示例10: 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(ClassMetadataInfo $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:
             // 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.
             $seqName = $this->targetPlatform instanceof Platforms\PostgreSQLPlatform ? $class->table['name'] . '_' . $class->columnNames[$class->identifier[0]] . '_seq' : null;
             $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($seqName));
             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'] = 1;
                 $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\AssignedGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_TABLE:
             throw new ORMException("TableGenerator not yet implemented.");
             break;
         default:
             throw new ORMException("Unknown generator type: " . $class->generatorType);
     }
 }
开发者ID:krishcdbry,项目名称:z-zangura,代码行数:52,代码来源:ClassMetadataFactory.php

示例11: evaluatePropertyAnnotations


//.........这里部分代码省略.........
                 $mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             /** @var ORM\JoinTable $joinTableAnnotation */
             if ($joinTableAnnotation = $this->reader->getPropertyAnnotation($property, ORM\JoinTable::class)) {
                 $joinTable = $this->evaluateJoinTableAnnotation($joinTableAnnotation, $property, $className, $mapping);
             } else {
                 $joinColumns = [['name' => null, 'referencedColumnName' => null]];
                 $joinTable = ['name' => $this->inferJoinTableNameFromClassAndPropertyName($className, $property->getName()), 'joinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property, self::MAPPING_MM_REGULAR), 'inverseJoinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property)];
             }
             $mapping['joinTable'] = $joinTable;
             $mapping['mappedBy'] = $manyToManyAnnotation->mappedBy;
             $mapping['inversedBy'] = $manyToManyAnnotation->inversedBy;
             if ($manyToManyAnnotation->cascade) {
                 $mapping['cascade'] = $manyToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             $mapping['indexBy'] = $manyToManyAnnotation->indexBy;
             $mapping['orphanRemoval'] = $manyToManyAnnotation->orphanRemoval;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OrderBy::class)) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapManyToMany($mapping);
         } elseif ($embeddedAnnotation = $this->reader->getPropertyAnnotation($property, ORM\Embedded::class)) {
             if ($embeddedAnnotation->class) {
                 $mapping['class'] = $embeddedAnnotation->class;
             } else {
                 // This will not happen currently, because "class" argument is required. It would be nice if that could be changed though.
                 $mapping['class'] = $mapping['targetEntity'];
             }
             $mapping['columnPrefix'] = $embeddedAnnotation->columnPrefix;
             $metadata->mapEmbedded($mapping);
         } else {
             $mapping['nullable'] = false;
             /** @var ORM\Column $columnAnnotation */
             if ($columnAnnotation = $this->reader->getPropertyAnnotation($property, ORM\Column::class)) {
                 $mapping = $this->addColumnToMappingArray($columnAnnotation, $mapping);
             }
             if (!isset($mapping['type'])) {
                 switch ($propertyMetaData['type']) {
                     case 'DateTime':
                         $mapping['type'] = 'datetime';
                         break;
                     case 'string':
                     case 'integer':
                     case 'boolean':
                     case 'float':
                     case 'array':
                         $mapping['type'] = $propertyMetaData['type'];
                         break;
                     default:
                         if (strpos($propertyMetaData['type'], '\\') !== false) {
                             if ($this->reflectionService->isClassAnnotatedWith($propertyMetaData['type'], Flow\ValueObject::class)) {
                                 $valueObjectAnnotation = $this->reflectionService->getClassAnnotation($propertyMetaData['type'], Flow\ValueObject::class);
                                 if ($valueObjectAnnotation->embedded === true) {
                                     $mapping['class'] = $propertyMetaData['type'];
                                     $mapping['columnPrefix'] = $mapping['columnName'];
                                     $metadata->mapEmbedded($mapping);
                                     // Leave switch and continue with next property
                                     continue 2;
                                 }
                                 $mapping['type'] = 'object';
                             } elseif (class_exists($propertyMetaData['type'])) {
                                 throw ORM\MappingException::missingRequiredOption($property->getName(), 'OneToOne', sprintf('The property "%s" in class "%s" has a non standard data type and doesn\'t define the type of the relation. You have to use one of these annotations: @OneToOne, @OneToMany, @ManyToOne, @ManyToMany', $property->getName(), $className));
                             }
                         } else {
                             throw ORM\MappingException::propertyTypeIsRequired($className, $property->getName());
                         }
                 }
             }
             if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnotation = $this->reader->getPropertyAnnotation($property, ORM\GeneratedValue::class)) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($generatedValueAnnotation->strategy)));
             }
             if ($this->reflectionService->isPropertyAnnotatedWith($className, $property->getName(), ORM\Version::class)) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, ORM\SequenceGenerator::class)) {
                 $metadata->setSequenceGeneratorDefinition(['sequenceName' => $seqGeneratorAnnotation->sequenceName, 'allocationSize' => $seqGeneratorAnnotation->allocationSize, 'initialValue' => $seqGeneratorAnnotation->initialValue]);
             } elseif ($this->reader->getPropertyAnnotation($property, ORM\TableGenerator::class) !== null) {
                 throw ORM\MappingException::tableIdGeneratorNotImplemented($className);
             } elseif ($customGeneratorAnnotation = $this->reader->getPropertyAnnotation($property, ORM\CustomIdGenerator::class)) {
                 $metadata->setCustomGeneratorDefinition(['class' => $customGeneratorAnnotation->class]);
             }
         }
         // Evaluate @Cache annotation
         if (($cacheAnnotation = $this->reader->getPropertyAnnotation($property, ORM\Cache::class)) !== null) {
             $metadata->enableAssociationCache($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnotation->usage), 'region' => $cacheAnnotation->region));
         }
     }
 }
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:101,代码来源:FlowAnnotationDriver.php

示例12: loadMetadataForClass


//.........这里部分代码省略.........
             }
             if (isset($fieldMapping['unique'])) {
                 $mapping['unique'] = (string) $fieldMapping['unique'] == "false" ? false : true;
             }
             if (isset($fieldMapping['options'])) {
                 $mapping['options'] = (array) $fieldMapping['options'];
             }
             if (isset($fieldMapping['nullable'])) {
                 $mapping['nullable'] = (string) $fieldMapping['nullable'] == "false" ? false : true;
             }
             if (isset($fieldMapping['version']) && $fieldMapping['version']) {
                 $metadata->setVersionMapping($mapping);
             }
             if (isset($fieldMapping['column-definition'])) {
                 $mapping['columnDefinition'] = (string) $fieldMapping['column-definition'];
             }
             $metadata->mapField($mapping);
         }
     }
     // Evaluate <id ...> mappings
     foreach ($xmlRoot->id as $idElement) {
         $mapping = array('id' => true, 'fieldName' => (string) $idElement['name'], 'type' => (string) $idElement['type']);
         if (isset($idElement['column'])) {
             $mapping['columnName'] = (string) $idElement['column'];
         }
         $metadata->mapField($mapping);
         if (isset($idElement->generator)) {
             $strategy = isset($idElement->generator['strategy']) ? (string) $idElement->generator['strategy'] : 'AUTO';
             $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $strategy));
         }
         // Check for SequenceGenerator/TableGenerator definition
         if (isset($idElement->{'sequence-generator'})) {
             $seqGenerator = $idElement->{'sequence-generator'};
             $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGenerator->{'sequence-name'}, 'allocationSize' => $seqGenerator->{'allocation-size'}, 'initialValue' => $seqGeneratorAnnot->{'initial-value'}));
         } else {
             if (isset($idElement->{'table-generator'})) {
                 throw MappingException::tableIdGeneratorNotImplemented($className);
             }
         }
     }
     // Evaluate <one-to-one ...> mappings
     if (isset($xmlRoot->{'one-to-one'})) {
         foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) {
             $mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']);
             if (isset($oneToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $oneToOneElement['fetch']);
             }
             if (isset($oneToOneElement['mapped-by'])) {
                 $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by'];
             } else {
                 $joinColumns = array();
                 if (isset($oneToOneElement->{'join-column'})) {
                     $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'});
                 } else {
                     if (isset($oneToOneElement->{'join-columns'})) {
                         foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                             $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                         }
                     }
                 }
                 $mapping['joinColumns'] = $joinColumns;
             }
             if (isset($oneToOneElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
             }
             if (isset($oneToOneElement->{'orphan-removal'})) {
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:67,代码来源:XmlDriver.php

示例13: _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(ClassMetadataInfo $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\AssignedGenerator());
             break;
         case ClassMetadata::GENERATOR_TYPE_TABLE:
             throw new ORMException("TableGenerator not yet implemented.");
             break;
         default:
             throw new ORMException("Unknown generator type: " . $class->generatorType);
     }
 }
开发者ID:poulikov,项目名称:readlater,代码行数:48,代码来源:ClassMetadataFactory.php

示例14: loadMetadataForClass


//.........这里部分代码省略.........
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['precision'] = $columnAnnot->precision;
             $mapping['scale'] = $columnAnnot->scale;
             $mapping['nullable'] = $columnAnnot->nullable;
             $mapping['unique'] = $columnAnnot->unique;
             if ($columnAnnot->options) {
                 $mapping['options'] = $columnAnnot->options;
             }
             if (isset($columnAnnot->name)) {
                 $mapping['columnName'] = $columnAnnot->name;
             }
             if (isset($columnAnnot->columnDefinition)) {
                 $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
             }
             if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $oneToOneAnnot->fetch);
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $oneToManyAnnot->fetch);
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $manyToOneAnnot->fetch);
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
                             $joinTable = array();
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:67,代码来源:AnnotationDriver.php


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