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


PHP ClassMetadata::setIdGeneratorType方法代码示例

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


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

示例1: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  *
  * @throws \Exception
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     if (!$metadata instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
         throw new \Exception('Error: class metadata object is the wrong type');
     }
     $refClass = new \ReflectionClass($className);
     $classDocBlock = $refClass->getDocComment();
     if (!$classDocBlock || strpos($classDocBlock, '@Table') === false) {
         $metadata->setPrimaryTable(['name' => $this->_getTableName($className)]);
     }
     $needAutoGenerator = false;
     foreach ($refClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
         $propName = $prop->getName();
         try {
             $mapping = $metadata->getFieldMapping($propName);
         } catch (MappingException $e) {
             $mapping = null;
         }
         if (!$mapping) {
             if ($propName == 'createdAt') {
                 if (!$this->isTransient($className) && !$refClass->isAbstract() && call_user_func($className . '::useAutoTimestamp')) {
                     $metadata->mapField(['fieldName' => 'createdAt', 'columnName' => call_user_func($className . '::getCreatedAtColumn'), 'type' => 'datetime']);
                 }
             } else {
                 if ($propName == 'updatedAt') {
                     if (!$this->isTransient($className) && !$refClass->isAbstract() && call_user_func($className . '::useAutoTimestamp')) {
                         $metadata->mapField(['fieldName' => 'updatedAt', 'columnName' => call_user_func($className . '::getUpdatedAtColumn'), 'type' => 'datetime']);
                     }
                 } else {
                     $columnName = Inflector::tableize($propName);
                     $fieldMap = ['fieldName' => $propName, 'columnName' => $columnName, 'type' => $this->_getDefaultDataType($columnName)];
                     if ($columnName == 'id') {
                         $fieldMap['id'] = true;
                         $fieldMap['autoincrement'] = true;
                         $fieldMap['unsigned'] = true;
                         $needAutoGenerator = true;
                     } else {
                         if (in_array($columnName, ['price', 'tax', 'amount', 'cost', 'total'])) {
                             // DECIMAL(10,2)
                             $fieldMap['precision'] = 10;
                             $fieldMap['scale'] = 2;
                         }
                     }
                     $metadata->mapField($fieldMap);
                 }
             }
         }
     }
     if ($needAutoGenerator && !$metadata->usesIdGenerator()) {
         $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO);
     }
 }
开发者ID:packaged,项目名称:mappers,代码行数:61,代码来源:AutoMappingDriver.php

示例2: loadMetadataForClass

 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     if ($className === 'Mapping\\Fixture\\Unmapped\\Timestampable') {
         $id = array();
         $id['fieldName'] = 'id';
         $id['type'] = 'integer';
         $id['nullable'] = false;
         $id['columnName'] = 'id';
         $id['id'] = true;
         $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_AUTO'));
         $metadata->mapField($id);
         $created = array();
         $created['fieldName'] = 'created';
         $created['type'] = 'datetime';
         $created['nullable'] = false;
         $created['columnName'] = 'created';
         $metadata->mapField($created);
     }
 }
开发者ID:n1c01a5,项目名称:DoctrineExtensions,代码行数:19,代码来源:CustomDriverTest.php

示例3: loadMetadataForClass


//.........这里部分代码省略.........
             }
             $metadata->mapField($mapping);
         }
     }
     foreach ($mappings as $mapping) {
         if (isset($mapping['version'])) {
             $metadata->setVersionMapping($mapping);
         }
         $metadata->mapField($mapping);
     }
     // Evaluate <id ...> mappings
     $associationIds = array();
     foreach ($xmlRoot->id as $idElement) {
         if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) {
             $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['length'])) {
             $mapping['length'] = (string) $idElement['length'];
         }
         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->{'custom-id-generator'})) {
                 $customGenerator = $idElement->{'custom-id-generator'};
                 $metadata->setCustomGeneratorDefinition(array('class' => (string) $customGenerator['class']));
             } 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'];
                 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:XmlDriver.php

示例4: loadMetadataForClass


//.........这里部分代码省略.........
     /* @var $property \ReflectionProperty */
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name) || $metadata->isInheritedEmbeddedClass($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Evaluate @Cache annotation
         if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Cache')) !== null) {
             $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), 'region' => $cacheAnnot->region));
         }
         // Check for JoinColumn/JoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
             $joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
         } else {
             if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
                 foreach ($joinColumnsAnnot->value as $joinColumn) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumn);
                 }
             }
         }
         // 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 = $this->columnToArray($property->getName(), $columnAnnot);
             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 ($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 ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 } else {
                     if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\CustomIdGenerator')) {
                         $metadata->setCustomGeneratorDefinition(array('class' => $customGeneratorAnnot->class));
                     }
                 }
             }
         } 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')) {
开发者ID:aschempp,项目名称:doctrine2,代码行数:67,代码来源:AnnotationDriver.php

示例5: loadMetadataForClass


//.........这里部分代码省略.........
             }
             $metadata->table['uniqueConstraints'][$uniqueYml['name']] = $unique;
         }
     }
     if (isset($element['options'])) {
         $metadata->table['options'] = $element['options'];
     }
     $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'];
             }
             if (isset($idElement['options'])) {
                 $mapping['options'] = $idElement['options'];
             }
             $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['customIdGenerator'])) {
                     $customGenerator = $idElement['customIdGenerator'];
                     $metadata->setCustomGeneratorDefinition(array('class' => (string) $customGenerator['class']));
                 } else {
                     if (isset($idElement['tableGenerator'])) {
                         throw MappingException::tableIdGeneratorNotImplemented($className);
                     }
                 }
             }
         }
     }
     // Evaluate fields
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $name => $fieldMapping) {
             $mapping = $this->columnToArray($name, $fieldMapping);
             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($mapping['version'])) {
                 $metadata->setVersionMapping($mapping);
                 unset($mapping['version']);
             }
             $metadata->mapField($mapping);
         }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:YamlDriver.php

示例6: loadMetadataForClass

    /**
     * {@inheritDoc}
     */
    public function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $this->reverseEngineerMappingFromDatabase();

        if (!isset($this->classToTableNames[$className])) {
            throw new \InvalidArgumentException("Unknown class " . $className);
        }

        $tableName = $this->classToTableNames[$className];

        $metadata->name = $className;
        $metadata->table['name'] = $tableName;

        $columns = $this->tables[$tableName]->getColumns();
        $indexes = $this->tables[$tableName]->getIndexes();
        try {
            $primaryKeyColumns = $this->tables[$tableName]->getPrimaryKey()->getColumns();
        } catch(SchemaException $e) {
            $primaryKeyColumns = array();
        }

        if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
            $foreignKeys = $this->tables[$tableName]->getForeignKeys();
        } else {
            $foreignKeys = array();
        }

        $allForeignKeyColumns = array();
        foreach ($foreignKeys as $foreignKey) {
            $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
        }

        $ids = array();
        $fieldMappings = array();
        foreach ($columns as $column) {
            $fieldMapping = array();

            if (in_array($column->getName(), $allForeignKeyColumns)) {
                continue;
            } else if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) {
                $fieldMapping['id'] = true;
            }

            $fieldMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $column->getName(), false);
            $fieldMapping['columnName'] = $column->getName();
            $fieldMapping['type'] = strtolower((string) $column->getType());

            if ($column->getType() instanceof \Doctrine\DBAL\Types\StringType) {
                $fieldMapping['length'] = $column->getLength();
                $fieldMapping['fixed'] = $column->getFixed();
            } else if ($column->getType() instanceof \Doctrine\DBAL\Types\IntegerType) {
                $fieldMapping['unsigned'] = $column->getUnsigned();
            }
            $fieldMapping['nullable'] = $column->getNotNull() ? false : true;

            if (isset($fieldMapping['id'])) {
                $ids[] = $fieldMapping;
            } else {
                $fieldMappings[] = $fieldMapping;
            }
        }

        if ($ids) {
            // We need to check for the columns here, because we might have associations as id as well.
            if (count($primaryKeyColumns) == 1) {
                $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
            }

            foreach ($ids as $id) {
                $metadata->mapField($id);
            }
        }

        foreach ($fieldMappings as $fieldMapping) {
            $metadata->mapField($fieldMapping);
        }

        foreach ($this->manyToManyTables as $manyTable) {
            foreach ($manyTable->getForeignKeys() as $foreignKey) {
                // foreign  key maps to the table of the current entity, many to many association probably exists
                if (strtolower($tableName) == strtolower($foreignKey->getForeignTableName())) {
                    $myFk = $foreignKey;
                    $otherFk = null;
                    foreach ($manyTable->getForeignKeys() as $foreignKey) {
                        if ($foreignKey != $myFk) {
                            $otherFk = $foreignKey;
                            break;
                        }
                    }

                    if (!$otherFk) {
                        // the definition of this many to many table does not contain
                        // enough foreign key information to continue reverse engineering.
                        continue;
                    }

                    $localColumn = current($myFk->getColumns());
//.........这里部分代码省略.........
开发者ID:nattaphat,项目名称:hgis,代码行数:101,代码来源:DatabaseDriver.php

示例7: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string                              $className
  * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     global $container;
     $builder = new ClassMetadataBuilder($metadata);
     $tableName = static::classToTableName($className);
     $this->loadDataContainer($tableName);
     try {
         /** @var ClassLoader $entitiesClassLoader */
         $entitiesClassLoader = $container['doctrine.orm.entitiesClassLoader'];
         if (!class_exists($className, false)) {
             $entitiesClassLoader->loadClass($className);
         }
         if (class_exists($className, false)) {
             $class = new \ReflectionClass($className);
         } else {
             $class = false;
         }
     } catch (\Exception $e) {
         $class = false;
     }
     if (!array_key_exists('TL_DCA', $GLOBALS)) {
         $GLOBALS['TL_DCA'] = array();
     }
     if (!array_key_exists($tableName, $GLOBALS['TL_DCA']) || !is_array($GLOBALS['TL_DCA'][$tableName])) {
         $GLOBALS['TL_DCA'][$tableName] = array('fields' => array());
     }
     $entityConfig = array();
     if (array_key_exists('entity', $GLOBALS['TL_DCA'][$tableName])) {
         $entityConfig = $GLOBALS['TL_DCA'][$tableName]['entity'];
     }
     if ($class && !$class->isInstantiable()) {
         $metadata->isMappedSuperclass = true;
     } elseif (array_key_exists('isMappedSuperclass', $entityConfig)) {
         $metadata->isMappedSuperclass = $entityConfig['isMappedSuperclass'];
     }
     // custom repository class
     if (array_key_exists('repositoryClass', $entityConfig)) {
         $metadata->setCustomRepositoryClass($entityConfig['repositoryClass']);
     } else {
         $metadata->setCustomRepositoryClass('Contao\\Doctrine\\ORM\\Repository');
     }
     // id generator
     if (array_key_exists('idGenerator', $entityConfig)) {
         $metadata->setIdGeneratorType($entityConfig['idGenerator']);
     } else {
         $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     }
     // indexes
     if (isset($entityConfig['indexes'])) {
         if (is_array($entityConfig['indexes'])) {
             foreach ($entityConfig['indexes'] as $name => $columns) {
                 if (is_array($columns)) {
                     $builder->addIndex($columns, $name);
                 } else {
                     throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes][%s] must be an array', $tableName, $name));
                 }
             }
         } else {
             throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes] must be an array', $tableName));
         }
     }
     // uniques
     if (isset($entityConfig['uniques'])) {
         if (is_array($entityConfig['uniques'])) {
             foreach ($entityConfig['uniques'] as $name => $columns) {
                 if (is_array($columns)) {
                     $builder->addUniqueConstraint($columns, $name);
                 } else {
                     throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques][%s] must be an array', $tableName, $name));
                 }
             }
         } else {
             throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques] must be an array', $tableName));
         }
     }
     $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
     $metadata->setPrimaryTable(array('name' => $tableName));
     $fields = (array) $GLOBALS['TL_DCA'][$tableName]['fields'];
     foreach ($fields as $fieldName => $fieldConfig) {
         $configured = array_key_exists('field', $fieldConfig) || array_key_exists('oneToOne', $fieldConfig) || array_key_exists('oneToMany', $fieldConfig) || array_key_exists('manyToOne', $fieldConfig) || array_key_exists('manyToMany', $fieldConfig);
         if (!$configured && empty($fieldConfig['inputType']) || $configured && $fieldConfig['field'] === false) {
             continue;
         }
         if (isset($fieldConfig['oneToOne'])) {
             $fieldConfig['oneToOne']['fieldName'] = $fieldName;
             $metadata->mapOneToOne($fieldConfig['oneToOne']);
         } elseif (isset($fieldConfig['oneToMany'])) {
             $fieldConfig['oneToMany']['fieldName'] = $fieldName;
             $metadata->mapOneToMany($fieldConfig['oneToMany']);
         } elseif (isset($fieldConfig['manyToOne'])) {
             $fieldConfig['manyToOne']['fieldName'] = $fieldName;
             $metadata->mapManyToOne($fieldConfig['manyToOne']);
         } elseif (isset($fieldConfig['manyToMany'])) {
             $fieldConfig['manyToMany']['fieldName'] = $fieldName;
//.........这里部分代码省略.........
开发者ID:bit3,项目名称:contao-doctrine-orm,代码行数:101,代码来源:ContaoDcaDriver.php


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