本文整理汇总了PHP中Propel\Generator\Model\Database::getTables方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::getTables方法的具体用法?PHP Database::getTables怎么用?PHP Database::getTables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Database
的用法示例。
在下文中一共展示了Database::getTables方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateDatabaseTables
protected function validateDatabaseTables(Database $database)
{
$phpNames = array();
foreach ($database->getTables() as $table) {
if (in_array($table->getPhpName(), $phpNames)) {
$this->errors[] = sprintf('Table "%s" declares a phpName already used in another table', $table->getName());
}
$phpNames[] = $table->getPhpName();
$this->validateTableAttributes($table);
$this->validateTableColumns($table);
}
}
示例2: compareTables
/**
* Returns the number of differences.
*
* Compares the tables of the fromDatabase and the toDatabase, and modifies
* the inner databaseDiff if necessary.
*
* @param boolean $caseInsensitive
* @return integer
*/
public function compareTables($caseInsensitive = false)
{
$fromDatabaseTables = $this->fromDatabase->getTables();
$toDatabaseTables = $this->toDatabase->getTables();
$databaseDifferences = 0;
$platform = $this->toDatabase->getPlatform() ?: $this->fromDatabase->getPlatform();
// check for new tables in $toDatabase
foreach ($toDatabaseTables as $table) {
if ($platform) {
$platform->normalizeTable($table);
}
if (!$this->fromDatabase->hasTable($table->getName(), $caseInsensitive) && !$table->isSkipSql()) {
$this->databaseDiff->addAddedTable($table->getName(), $table);
$databaseDifferences++;
}
}
// check for removed tables in $toDatabase
foreach ($fromDatabaseTables as $table) {
if (!$this->toDatabase->hasTable($table->getName(), $caseInsensitive) && !$table->isSkipSql()) {
$this->databaseDiff->addRemovedTable($table->getName(), $table);
$databaseDifferences++;
}
}
// check for table differences
foreach ($fromDatabaseTables as $fromTable) {
if ($this->toDatabase->hasTable($fromTable->getName(), $caseInsensitive)) {
$toTable = $this->toDatabase->getTable($fromTable->getName(), $caseInsensitive);
$databaseDiff = TableComparator::computeDiff($fromTable, $toTable, $caseInsensitive);
if ($databaseDiff) {
$this->databaseDiff->addModifiedTable($fromTable->getName(), $databaseDiff);
$databaseDifferences++;
}
}
}
$renamed = [];
// check for table renamings
foreach ($this->databaseDiff->getAddedTables() as $addedTableName => $addedTable) {
foreach ($this->databaseDiff->getRemovedTables() as $removedTableName => $removedTable) {
if (!in_array($addedTableName, $renamed) && !TableComparator::computeDiff($addedTable, $removedTable, $caseInsensitive)) {
// no difference except the name, that's probably a renaming
$renamed[] = $addedTableName;
$this->databaseDiff->addRenamedTable($removedTableName, $addedTableName);
$this->databaseDiff->removeAddedTable($addedTableName);
$this->databaseDiff->removeRemovedTable($removedTableName);
$databaseDifferences--;
}
}
}
return $databaseDifferences;
}
示例3: createFormTypeFromDatabase
/**
* Create FormTypes from a given database, bundle and models.
*
* @param BundleInterface $bundle The bundle for which the FormTypes will be generated.
* @param Database $database The database to inspect.
* @param array $models The models to build.
* @param OutputInterface $output An OutputInterface instance
* @param boolean $force Override files if present.
*/
protected function createFormTypeFromDatabase(BundleInterface $bundle, Database $database, $models, OutputInterface $output, $force = false)
{
$dir = $this->createDirectory($bundle, $output);
foreach ($database->getTables() as $table) {
if (0 < count($models) && !in_array($table->getPhpName(), $models)) {
continue;
}
$file = new \SplFileInfo(sprintf('%s/%sType.php', $dir, $table->getPhpName()));
if (!file_exists($file) || true === $force) {
$this->writeFormType($bundle, $table, $file, $force, $output);
} else {
$output->writeln(sprintf('File <comment>%-60s</comment> exists, skipped. Try the <info>--force</info> option.', $this->getRelativeFileName($file)));
}
}
}
示例4: testCreateNewDatabase
public function testCreateNewDatabase()
{
$database = new Database('bookstore');
$this->assertSame('bookstore', $database->getName());
$this->assertSame('YAML', $database->getDefaultStringFormat());
$this->assertSame('native', $database->getDefaultIdMethod());
$this->assertSame('underscore', $database->getDefaultPhpNamingMethod());
$this->assertEmpty($database->getTablePrefix());
$this->assertNull($database->getParentSchema());
$this->assertNull($database->getDomain('BOOLEAN'));
$this->assertNull($database->getGeneratorConfig());
$this->assertCount(0, $database->getTables());
$this->assertSame(0, $database->countTables());
$this->assertFalse($database->isHeavyIndexing());
$this->assertFalse($database->getHeavyIndexing());
$this->assertFalse($database->hasTableByPhpName('foo'));
$this->assertNull($database->getTableByPhpName('foo'));
$this->assertFalse($database->hasBehavior('foo'));
$this->assertNull($database->getBehavior('foo'));
}
示例5: validateDatabaseTables
protected function validateDatabaseTables(Database $database)
{
$phpNames = [];
$namespaces = [];
foreach ($database->getTables() as $table) {
$list =& $phpNames;
if ($table->getNamespace()) {
if (!isset($namespaces[$table->getNamespace()])) {
$namespaces[$table->getNamespace()] = [];
}
$list =& $namespaces[$table->getNamespace()];
}
if (in_array($table->getPhpName(), $list)) {
$this->errors[] = sprintf('Table "%s" declares a phpName already used in another table', $table->getName());
}
$list[] = $table->getPhpName();
$this->validateTableAttributes($table);
$this->validateTableColumns($table);
}
}
示例6: getAddSchemasDDL
public function getAddSchemasDDL(Database $database)
{
$ret = '';
$schemas = array();
foreach ($database->getTables() as $table) {
$vi = $table->getVendorInfoForType('pgsql');
if ($vi->hasParameter('schema') && !isset($schemas[$vi->getParameter('schema')])) {
$schemas[$vi->getParameter('schema')] = true;
$ret .= $this->getAddSchemaDDL($table);
}
}
return $ret;
}
示例7: appendDatabaseNode
/**
* Appends the generated <database> XML node to its parent node.
*
* @param Database $database The Database model instance
* @param \DOMNode $parentNode The parent DOMNode object
*/
private function appendDatabaseNode(Database $database, \DOMNode $parentNode)
{
$databaseNode = $parentNode->appendChild($this->document->createElement('database'));
$databaseNode->setAttribute('name', $database->getName());
$databaseNode->setAttribute('defaultIdMethod', $database->getDefaultIdMethod());
if ($package = $database->getPackage()) {
$databaseNode->setAttribute('package', $package);
}
if ($schema = $database->getSchema()) {
$databaseNode->setAttribute('schema', $schema);
}
if ($namespace = $database->getNamespace()) {
$databaseNode->setAttribute('namespace', $namespace);
}
if ($baseClass = $database->getBaseClass()) {
$databaseNode->setAttribute('baseClass', $baseClass);
}
if ($baseQueryClass = $database->getBaseQueryClass()) {
$databaseNode->setAttribute('baseQueryClass', $baseQueryClass);
}
if ($defaultNamingMethod = $database->getDefaultPhpNamingMethod()) {
$databaseNode->setAttribute('defaultPhpNamingMethod', $defaultNamingMethod);
}
$defaultAccessorVisibility = $database->getDefaultAccessorVisibility();
if ($defaultAccessorVisibility !== Database::VISIBILITY_PUBLIC) {
$databaseNode->setAttribute('defaultAccessorVisibility', $defaultAccessorVisibility);
}
$defaultMutatorVisibility = $database->getDefaultMutatorVisibility();
if ($defaultMutatorVisibility !== Database::VISIBILITY_PUBLIC) {
$databaseNode->setAttribute('defaultMutatorVisibility', $defaultMutatorVisibility);
}
$defaultStringFormat = $database->getDefaultStringFormat();
if (Database::DEFAULT_STRING_FORMAT !== $defaultStringFormat) {
$databaseNode->setAttribute('defaultStringFormat', $defaultStringFormat);
}
if ($database->isHeavyIndexing()) {
$databaseNode->setAttribute('heavyIndexing', 'true');
}
if ($tablePrefix = $database->getTablePrefix()) {
$databaseNode->setAttribute('tablePrefix', $tablePrefix);
}
if ($database->isIdentifierQuotingEnabled()) {
$databaseNode->setAttribute('identifierQuoting', 'true');
}
/*
FIXME - Before we can add support for domains in the schema, we need
to have a method of the Column that indicates whether the column was mapped
to a SPECIFIC domain (since Column->getDomain() will always return a Domain object)
foreach ($this->domainMap as $domain) {
$this->appendDomainNode($databaseNode);
}
*/
foreach ($database->getVendorInformation() as $vendorInformation) {
$this->appendVendorInformationNode($vendorInformation, $databaseNode);
}
foreach ($database->getTables() as $table) {
$this->appendTableNode($table, $databaseNode);
}
}
示例8: compareTables
/**
* Returns the number of differences.
*
* Compares the tables of the fromDatabase and the toDatabase, and modifies
* the inner databaseDiff if necessary.
*
* @param boolean $caseInsensitive
* @return integer
*/
public function compareTables($caseInsensitive = false)
{
$fromDatabaseTables = $this->fromDatabase->getTables();
$toDatabaseTables = $this->toDatabase->getTables();
$databaseDifferences = 0;
// check for new tables in $toDatabase
foreach ($toDatabaseTables as $table) {
if ($this->isTableExcluded($table)) {
continue;
}
if (!$this->fromDatabase->hasTable($table->getName(), $caseInsensitive) && !$table->isSkipSql()) {
$this->databaseDiff->addAddedTable($table->getName(), $table);
$databaseDifferences++;
}
}
// check for removed tables in $toDatabase
if ($this->getRemoveTable()) {
foreach ($fromDatabaseTables as $table) {
if ($this->isTableExcluded($table)) {
continue;
}
if (!$this->toDatabase->hasTable($table->getName(), $caseInsensitive) && !$table->isSkipSql()) {
$this->databaseDiff->addRemovedTable($table->getName(), $table);
$databaseDifferences++;
}
}
}
// check for table differences
foreach ($fromDatabaseTables as $fromTable) {
if ($this->isTableExcluded($fromTable)) {
continue;
}
if ($this->toDatabase->hasTable($fromTable->getName(), $caseInsensitive)) {
$toTable = $this->toDatabase->getTable($fromTable->getName(), $caseInsensitive);
$databaseDiff = TableComparator::computeDiff($fromTable, $toTable, $caseInsensitive);
if ($databaseDiff) {
$this->databaseDiff->addModifiedTable($fromTable->getName(), $databaseDiff);
$databaseDifferences++;
}
}
}
// check for table renamings
foreach ($this->databaseDiff->getAddedTables() as $addedTableName => $addedTable) {
foreach ($this->databaseDiff->getRemovedTables() as $removedTableName => $removedTable) {
if (!TableComparator::computeDiff($addedTable, $removedTable, $caseInsensitive)) {
// no difference except the name, that's probably a renaming
if ($this->getWithRenaming()) {
$this->databaseDiff->addRenamedTable($removedTableName, $addedTableName);
$this->databaseDiff->removeAddedTable($addedTableName);
$this->databaseDiff->removeRemovedTable($removedTableName);
$databaseDifferences--;
} else {
$this->databaseDiff->addPossibleRenamedTable($removedTableName, $addedTableName);
}
// skip to the next added table
break;
}
}
}
return $databaseDifferences;
}
示例9: getTables
/**
* Returns the list of all tables in the same database.
*
* @return Table[] A collection of Table instance
*/
protected function getTables()
{
return $this->database->getTables();
}