本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::setIdGeneratorType方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::setIdGeneratorType方法的具体用法?PHP ClassMetadataInfo::setIdGeneratorType怎么用?PHP ClassMetadataInfo::setIdGeneratorType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo
的用法示例。
在下文中一共展示了ClassMetadataInfo::setIdGeneratorType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
* @param string $document
* @param array $fields
* @param Boolean $withRepository
* @throws \RuntimeException
*/
public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
{
$config = $this->documentManager->getConfiguration();
$config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
$documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
$documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
if (file_exists($documentPath)) {
throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
}
$class = new ClassMetadataInfo($documentClass);
if ($withRepository) {
$class->setCustomRepositoryClass($documentClass . 'Repository');
}
$class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
foreach ($fields as $field) {
$class->mapField($field);
}
$documentGenerator = $this->getDocumentGenerator();
$documentCode = $documentGenerator->generateDocumentClass($class);
$this->filesystem->mkdir(dirname($documentPath));
file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
if ($withRepository) {
$path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
$this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
}
}
示例2: generateBookDocumentFixture
public function generateBookDocumentFixture()
{
$metadata = new ClassMetadataInfo($this->namespace . '\\DocumentGeneratorBook');
$metadata->namespace = $this->namespace;
$metadata->customRepositoryClassName = $this->namespace . '\\DocumentGeneratorBookRepository';
$metadata->collection = 'book';
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->mapOneReference(array('fieldName' => 'author', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Tools\\DocumentGeneratorAuthor'));
$metadata->mapManyReference(array('fieldName' => 'comments', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Tools\\DocumentGeneratorComment'));
$metadata->addLifecycleCallback('loading', 'postLoad');
$metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$this->generator->writeDocumentClass($metadata, $this->tmpDir);
return $metadata;
}