本文整理汇总了PHP中Propel\Generator\Model\Database::setDefaultIdMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::setDefaultIdMethod方法的具体用法?PHP Database::setDefaultIdMethod怎么用?PHP Database::setDefaultIdMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Database
的用法示例。
在下文中一共展示了Database::setDefaultIdMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildModel
/**
* Builds the model classes from the database schema.
*
* @return Database The built-out Database (with all tables, etc.)
*/
protected function buildModel()
{
$config = $this->getGeneratorConfig();
$connection = $this->getConnection();
$databaseName = $config->getConfigProperty('reverse.connection');
$database = new Database($this->getDatabaseName());
$database->setPlatform($config->getConfiguredPlatform($connection), $databaseName);
$database->setDefaultIdMethod(IdMethod::NATIVE);
$buildConnection = $config->getBuildConnection($databaseName);
$this->log(sprintf('Reading database structure of database `%s` using dsn `%s`', $this->getDatabaseName(), $buildConnection['dsn']));
$parser = $config->getConfiguredSchemaParser($connection, $databaseName);
$this->log(sprintf('SchemaParser `%s` chosen', get_class($parser)));
$nbTables = $parser->parse($database);
$excludeTables = $config->getConfigProperty('exclude_tables');
$tables = [];
foreach ($database->getTables() as $table) {
/* Was copypasted from DatabaseComparator::isTableExcluded() */
$skip = false;
$tablename = $table->getName();
if (in_array($tablename, $excludeTables)) {
$skip = true;
} else {
foreach ($excludeTables as $exclude_tablename) {
if (preg_match('/^' . str_replace('*', '.*', $exclude_tablename) . '$/', $tablename)) {
$skip = true;
}
}
}
$skip && $database->removeTable($table);
}
$this->log(sprintf('Successfully reverse engineered %d tables', $nbTables));
return $database;
}
示例2: buildModel
/**
* Builds the model classes from the database schema.
*
* @return Database The built-out Database (with all tables, etc.)
*/
protected function buildModel()
{
$config = $this->getGeneratorConfig();
$connection = $this->getConnection();
$this->log('Reading database structure...');
$database = new Database($this->getDatabaseName());
$database->setPlatform($config->getConfiguredPlatform($connection));
$database->setDefaultIdMethod(IdMethod::NATIVE);
$parser = $config->getConfiguredSchemaParser($connection);
$nbTables = $parser->parse($database);
$this->log(sprintf('Successfully reverse engineered %d tables', $nbTables));
return $database;
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$configOptions = [];
if ($this->hasInputOption('connection', $input)) {
foreach ($input->getOption('connection') as $conn) {
$configOptions += $this->connectionToProperties($conn);
}
}
if ($this->hasInputOption('migration-table', $input)) {
$configOptions['propel']['migrations']['tableName'] = $input->getOption('migration-table');
}
if ($this->hasInputOption('schema-dir', $input)) {
$configOptions['propel']['paths']['schemaDir'] = $input->getOption('schema-dir');
}
if ($this->hasInputOption('output-dir', $input)) {
$configOptions['propel']['paths']['migrationDir'] = $input->getOption('output-dir');
}
$generatorConfig = $this->getGeneratorConfig($configOptions, $input);
$this->createDirectory($generatorConfig->getSection('paths')['migrationDir']);
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
$manager->setSchemas($this->getSchemas($generatorConfig->getSection('paths')['schemaDir'], $input->getOption('recursive')));
$connections = [];
$optionConnections = $input->getOption('connection');
if (!$optionConnections) {
$connections = $generatorConfig->getBuildConnections();
} else {
foreach ($optionConnections as $connection) {
list($name, $dsn, $infos) = $this->parseConnection($connection);
$connections[$name] = array_merge(['dsn' => $dsn], $infos);
}
}
$manager->setConnections($connections);
$manager->setMigrationTable($generatorConfig->getConfigProperty('migrations.tableName'));
$manager->setWorkingDirectory($generatorConfig->getSection('paths')['migrationDir']);
if ($manager->hasPendingMigrations()) {
throw new RuntimeException('Uncommitted migrations have been found ; you should either execute or delete them before rerunning the \'diff\' task');
}
$totalNbTables = 0;
$reversedSchema = new Schema();
foreach ($manager->getDatabases() as $appDatabase) {
$name = $appDatabase->getName();
if (!($params = @$connections[$name])) {
$output->writeln(sprintf('<info>No connection configured for database "%s"</info>', $name));
}
if ($input->getOption('verbose')) {
$output->writeln(sprintf('Connecting to database "%s" using DSN "%s"', $name, $params['dsn']));
}
$conn = $manager->getAdapterConnection($name);
$platform = $generatorConfig->getConfiguredPlatform($conn, $name);
if (!$platform->supportsMigrations()) {
$output->writeln(sprintf('Skipping database "%s" since vendor "%s" does not support migrations', $name, $platform->getDatabaseType()));
continue;
}
$additionalTables = [];
foreach ($appDatabase->getTables() as $table) {
if ($table->getSchema() && $table->getSchema() != $appDatabase->getSchema()) {
$additionalTables[] = $table;
}
}
if ($input->getOption('disable-identifier-quoting')) {
$platform->setIdentifierQuoting(false);
}
$database = new Database($name);
$database->setPlatform($platform);
$database->setSchema($appDatabase->getSchema());
$database->setDefaultIdMethod(IdMethod::NATIVE);
$parser = $generatorConfig->getConfiguredSchemaParser($conn, $name);
$nbTables = $parser->parse($database, $additionalTables);
$reversedSchema->addDatabase($database);
$totalNbTables += $nbTables;
if ($input->getOption('verbose')) {
$output->writeln(sprintf('%d tables found in database "%s"', $nbTables, $name), Output::VERBOSITY_VERBOSE);
}
}
if ($totalNbTables) {
$output->writeln(sprintf('%d tables found in all databases.', $totalNbTables));
} else {
$output->writeln('No table found in all databases');
}
// comparing models
$output->writeln('Comparing models...');
$tableRenaming = $input->getOption('table-renaming');
$migrationsUp = [];
$migrationsDown = [];
$removeTable = !$input->getOption('skip-removed-table');
$excludedTables = $input->getOption('skip-tables');
foreach ($reversedSchema->getDatabases() as $database) {
$name = $database->getName();
if ($input->getOption('verbose')) {
$output->writeln(sprintf('Comparing database "%s"', $name));
}
if (!($appDataDatabase = $manager->getDatabase($name))) {
$output->writeln(sprintf('<error>Database "%s" does not exist in schema.xml. Skipped.</error>', $name));
continue;
}
$configManager = new ConfigurationManager();
//.........这里部分代码省略.........
示例4: testSetDefaultIdMethod
public function testSetDefaultIdMethod()
{
$database = new Database();
$database->setDefaultIdMethod('native');
$this->assertSame('native', $database->getDefaultIdMethod());
}
示例5: buildModel
/**
* Builds the model classes from the database schema.
*
* @return Database The built-out Database (with all tables, etc.)
*/
protected function buildModel()
{
$config = $this->getGeneratorConfig();
$connection = $this->getConnection();
$databaseName = $config->getConfigProperty('reverse.connection');
$database = new Database($this->getDatabaseName());
$database->setPlatform($config->getConfiguredPlatform($connection), $databaseName);
$database->setDefaultIdMethod(IdMethod::NATIVE);
$buildConnection = $config->getBuildConnection($databaseName);
$this->log(sprintf('Reading database structure of database `%s` using dsn `%s`', $this->getDatabaseName(), $buildConnection['dsn']));
$parser = $config->getConfiguredSchemaParser($connection, $databaseName);
$this->log(sprintf('SchemaParser `%s` chosen', get_class($parser)));
$nbTables = $parser->parse($database);
$this->log(sprintf('Successfully reverse engineered %d tables', $nbTables));
return $database;
}
示例6: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$generatorConfig = $this->getGeneratorConfig(array('propel.platform.class' => $input->getOption('platform'), 'propel.reverse.parser.class' => $this->getReverseClass($input), 'propel.migration.table' => $input->getOption('migration-table')), $input);
$this->createDirectory($input->getOption('output-dir'));
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
$manager->setSchemas($this->getSchemas($input->getOption('input-dir')));
$connections = array();
$optionConnections = $input->getOption('connection');
if (!$optionConnections) {
$connections = $generatorConfig->getBuildConnections($input->getOption('input-dir'));
} else {
foreach ($optionConnections as $connection) {
list($name, $dsn, $infos) = $this->parseConnection($connection);
$connections[$name] = array_merge(array('dsn' => $dsn), $infos);
}
}
$manager->setConnections($connections);
$manager->setMigrationTable($input->getOption('migration-table'));
$manager->setWorkingDirectory($input->getOption('output-dir'));
if ($manager->hasPendingMigrations()) {
throw new RuntimeException('Uncommitted migrations have been found ; you should either execute or delete them before rerunning the \'diff\' task');
}
$totalNbTables = 0;
$schema = new Schema();
foreach ($connections as $name => $params) {
if ($input->getOption('verbose')) {
$output->writeln(sprintf('Connecting to database "%s" using DSN "%s"', $name, $params['dsn']));
}
$conn = $manager->getAdapterConnection($name);
$platform = $generatorConfig->getConfiguredPlatform($conn, $name);
if (!$platform->supportsMigrations()) {
$output->writeln(sprintf('Skipping database "%s" since vendor "%s" does not support migrations', $name, $platform->getDatabaseType()));
continue;
}
$database = new Database($name);
$database->setPlatform($platform);
$database->setDefaultIdMethod(IdMethod::NATIVE);
$parser = $generatorConfig->getConfiguredSchemaParser($conn);
$nbTables = $parser->parse($database, $this);
$schema->addDatabase($database);
$totalNbTables += $nbTables;
if ($input->getOption('verbose')) {
$output->writeln(sprintf('%d tables found in database "%s"', $nbTables, $name), Output::VERBOSITY_VERBOSE);
}
}
if ($totalNbTables) {
$output->writeln(sprintf('%d tables found in all databases.', $totalNbTables));
} else {
$output->writeln('No table found in all databases');
}
$appDatasFromXml = $manager->getDataModels();
$appDataFromXml = array_pop($appDatasFromXml);
// comparing models
$output->writeln('Comparing models...');
$migrationsUp = array();
$migrationsDown = array();
foreach ($schema->getDatabases() as $database) {
$name = $database->getName();
if ($input->getOption('verbose')) {
$output->writeln(sprintf('Comparing database "%s"', $name));
}
if (!$appDataFromXml->hasDatabase($name)) {
// FIXME: tables present in database but not in XML
continue;
}
$databaseDiff = DatabaseComparator::computeDiff($database, $appDataFromXml->getDatabase($name));
if (!$databaseDiff) {
if ($input->getOption('verbose')) {
$output->writeln(sprintf('Same XML and database structures for datasource "%s" - no diff to generate', $name));
}
continue;
}
$output->writeln(sprintf('Structure of database was modified in datasource "%s": %s', $name, $databaseDiff->getDescription()));
$platform = $generatorConfig->getConfiguredPlatform(null, $name);
$migrationsUp[$name] = $platform->getModifyDatabaseDDL($databaseDiff);
$migrationsDown[$name] = $platform->getModifyDatabaseDDL($databaseDiff->getReverseDiff());
}
if (!$migrationsUp) {
$output->writeln('Same XML and database structures for all datasource - no diff to generate');
return;
}
$timestamp = time();
$migrationFileName = $manager->getMigrationFileName($timestamp);
$migrationClassBody = $manager->getMigrationClassBody($migrationsUp, $migrationsDown, $timestamp);
$file = $input->getOption('output-dir') . DIRECTORY_SEPARATOR . $migrationFileName;
file_put_contents($file, $migrationClassBody);
$output->writeln(sprintf('"%s" file successfully created.', $file));
if (null !== ($editorCmd = $input->getOption('editor'))) {
$output->writeln(sprintf('Using "%s" as text editor', $editorCmd));
shell_exec($editorCmd . ' ' . escapeshellarg($file));
} else {
$output->writeln('Please review the generated SQL statements, and add data migration code if necessary.');
$output->writeln('Once the migration class is valid, call the "migrate" task to execute it.');
}
}