本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool::getCreateSchemaSql方法的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool::getCreateSchemaSql方法的具体用法?PHP SchemaTool::getCreateSchemaSql怎么用?PHP SchemaTool::getCreateSchemaSql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\SchemaTool
的用法示例。
在下文中一共展示了SchemaTool::getCreateSchemaSql方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if ($this->option('sql')) {
$this->info('Outputting create query:');
$sql = $this->tool->getCreateSchemaSql($this->metadata->getAllMetadata());
$this->info(implode(';' . PHP_EOL, $sql));
} else {
$this->info('Creating database schema...');
$this->tool->createSchema($this->metadata->getAllMetadata());
$this->info('Schema has been created!');
}
}
示例2: updateEntity
public function updateEntity(array $entity)
{
$metadata = $this->getMetadata($entity);
$tool = new SchemaTool($this->_em);
$queries = $tool->getCreateSchemaSql($metadata);
return $this->persist($queries ?: array());
}
示例3: testGetCreateSchemaSql4
/**
* @group DBAL-204
*/
public function testGetCreateSchemaSql4()
{
$classes = array($this->_em->getClassMetadata(__NAMESPACE__ . '\\MysqlSchemaNamespacedEntity'));
$tool = new SchemaTool($this->_em);
$sql = $tool->getCreateSchemaSql($classes);
$this->assertEquals(0, count($sql));
}
示例4: fire
public function fire()
{
if ($this->option('sql')) {
$this->info('Outputting create query:' . PHP_EOL);
$sql = $this->tool->getCreateSchemaSql($this->metadata->getAllMetadata());
$this->info(implode(';' . PHP_EOL, $sql) . ';');
} else {
if ($this->option('commit')) {
$this->info('Creating database schema...');
$this->tool->createSchema($this->metadata->getAllMetadata());
$this->info('Schema has been created!');
} else {
$this->comment("Warning: this command can cause data loss. Run with --sql or --commit.");
}
}
}
示例5: testGetCreateSchemaSql3
public function testGetCreateSchemaSql3()
{
$classes = array($this->_em->getClassMetadata('Doctrine\\Tests\\Models\\Generic\\BooleanModel'));
$tool = new SchemaTool($this->_em);
$sql = $tool->getCreateSchemaSql($classes);
$this->assertEquals(1, count($sql));
$this->assertEquals("CREATE TABLE boolean_model (id INT AUTO_INCREMENT NOT NULL, booleanField TINYINT(1) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]);
}
示例6: getBundleSqlSchema
private function getBundleSqlSchema()
{
$sql = array();
foreach ($this->_application->getBundles() as $bundle) {
$classes = $this->_getBundleSchema($bundle);
$sql = array_merge($sql, $this->_schemaTool->getCreateSchemaSql($classes));
}
return $sql;
}
示例7: testGetCreateSchemaSql3
public function testGetCreateSchemaSql3()
{
$classes = array($this->_em->getClassMetadata('Doctrine\\Tests\\Models\\Generic\\BooleanModel'));
$tool = new SchemaTool($this->_em);
$sql = $tool->getCreateSchemaSql($classes);
$this->assertEquals(2, count($sql));
$this->assertEquals("CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id))", $sql[0]);
$this->assertEquals("CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1", $sql[1]);
}
示例8: testGetCreateSchemaSql
public function testGetCreateSchemaSql()
{
$driver = new \Doctrine\Tests\Mocks\DriverMock();
$conn = new \Doctrine\Tests\Mocks\ConnectionMock(array(), $driver);
$conn->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform());
$em = $this->_getTestEntityManager($conn);
$classes = array($em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser'), $em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber'));
$exporter = new SchemaTool($em);
$sql = $exporter->getCreateSchemaSql($classes);
$this->assertEquals(count($sql), 8);
}
示例9: executeSchemaCommand
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
if ($input->getOption('dump-sql') === true) {
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
} else {
$output->write('Creating database schema...' . PHP_EOL);
$schemaTool->createSchema($metadatas);
$output->write('Database schema created successfully!' . PHP_EOL);
}
}
示例10: executeSchemaCommand
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
$output->write('ATTENTION: This operation should not be executed in an production enviroment.' . PHP_EOL . PHP_EOL);
if ($input->getOption('dump-sql') === true) {
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
} else {
$output->write('Creating database schema...' . PHP_EOL);
$schemaTool->createSchema($metadatas);
$output->write('Database schema created successfully!' . PHP_EOL);
}
}
示例11: generate
/**
* Generate SQL for creating schema
*
* @return string
*/
public function generate()
{
AnnotationRegistry::registerFile(__DIR__ . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
$driver = new AnnotationDriver(new CachedReader(new AnnotationReader(), new ArrayCache()), array(__DIR__ . '/../library/Xi/Filelib/Backend/Adapter/DoctrineOrm/Entity'));
$config = new Configuration();
$config->setMetadataDriverImpl($driver);
$config->setProxyDir(ROOT_TESTS . '/data/temp');
$config->setProxyNamespace('Proxies');
$em = EntityManager::create($this->connectionOptions, $config);
$st = new SchemaTool($em);
$metadata = $st->getCreateSchemaSql($em->getMetadataFactory()->getAllMetadata());
return join(";\n", $metadata) . ";\n";
}
示例12: installPluginSchema
/**
* Install plugin schema based on Doctrine metadata
*
* @param array $metadata
* @param MauticFactory $factory
*
* @throws \Doctrine\DBAL\ConnectionException
* @throws \Doctrine\ORM\ORMException
* @throws \Exception
*/
public static function installPluginSchema(array $metadata, MauticFactory $factory)
{
$db = $factory->getDatabase();
$schemaTool = new SchemaTool($factory->getEntityManager());
$installQueries = $schemaTool->getCreateSchemaSql($metadata);
$db->beginTransaction();
try {
foreach ($installQueries as $q) {
$db->query($q);
}
$db->commit();
} catch (\Exception $e) {
$db->rollback();
throw $e;
}
}
示例13: executeSchemaCommand
/**
* {@inheritdoc}
*/
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
if ($input->getOption('dump-sql')) {
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
$output->writeln(implode(';' . PHP_EOL, $sqls) . ';');
} else {
$output->writeln('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL);
$output->writeln('Creating database schema...');
$schemaTool->createSchema($metadatas);
$output->writeln('Database schema created successfully!');
}
// Insert fake data to database
if ($input->getOption('fakedata')) {
$this->_insertFakeData($output);
}
return 0;
}
示例14: fire
/**
* Execute the console command.
*
* @param ManagerRegistry $registry
*/
public function fire(ManagerRegistry $registry)
{
$names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames();
if (!$this->option('sql')) {
$this->error('ATTENTION: This operation should not be executed in a production environment.');
}
foreach ($names as $name) {
$em = $registry->getManager($name);
$tool = new SchemaTool($em);
$this->message('Creating database schema for <info>' . $name . '</info> entity manager...', 'blue');
if ($this->option('sql')) {
$sql = $tool->getCreateSchemaSql($em->getMetadataFactory()->getAllMetadata());
$this->comment(' ' . implode('; ' . PHP_EOL, $sql));
} else {
$tool->createSchema($em->getMetadataFactory()->getAllMetadata());
}
}
$this->info('Database schema created successfully!');
}
示例15: _doRun
protected function _doRun(HelperSet $helperSet)
{
if ($this->installSqlFile === null) {
throw new \BuildException("Schema SQL file is not set.");
}
if (!is_dir(dirname($this->installSqlFile))) {
throw new \BuildException("Schema SQL directory is not a valid directory.");
}
if (!is_writable(dirname($this->installSqlFile))) {
throw new \BuildException("Schema SQL directory is not writable.");
}
$emHelper = $helperSet->get('em');
$em = $emHelper->getEntityManager();
$schemaTool = new SchemaTool($em);
$cmf = $em->getMetadataFactory();
$classes = $cmf->getAllMetadata();
$sql = $schemaTool->getCreateSchemaSql($classes);
$code = sprintf("<?php\n\nreturn %s;\n", var_export($sql, true));
file_put_contents($this->installSqlFile, $code);
$this->log("Wrote schema SQL to file {$this->installSqlFile}");
}