本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::setIdGenerator方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setIdGenerator方法的具体用法?PHP ClassMetadata::setIdGenerator怎么用?PHP ClassMetadata::setIdGenerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setIdGenerator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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')));
}
示例2: remapIdentifier
/**
* @param string $property
* @param array $mapping
*/
protected function remapIdentifier($property, array &$mapping)
{
if ($mapping['type'] !== 'rid') {
return;
}
$identifier = $this->meta->identifier;
if (count($identifier) !== 1 or $this->meta->identifier[0] !== $property) {
return;
}
if ($mapping['columnName'] === '@rid') {
return;
}
$mapping['columnName'] = '@rid';
$oldColumn = array_search($property, $this->meta->fieldNames);
unset($this->meta->fieldNames[$oldColumn]);
$this->meta->fieldNames['@rid'] = $property;
$this->meta->columnNames[$property] = '@rid';
$this->meta->setIdGenerator(new BigIntegerIdentityGenerator());
}
示例3: _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);
}
}