本文整理汇总了PHP中Doctrine\DBAL\Schema\Table::getColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::getColumns方法的具体用法?PHP Table::getColumns怎么用?PHP Table::getColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Schema\Table
的用法示例。
在下文中一共展示了Table::getColumns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getColumns
/**
* Get array of Doctrine\DBAL\Schema\Column instances for the table.
*
* @return array
*/
public function getColumns()
{
if (empty($this->columns)) {
$this->columns = $this->toTable->getColumns();
}
return $this->columns;
}
示例2: describe
public function describe($namespace) : array
{
if (substr($namespace, -1) != "\\") {
$namespace .= "\\";
}
$tableIdentifier = $this->dbalSchemaTable->getName();
$methods = ['fetchAll' => $this->describeQueryMethod([], $this->describeQuerySelect('*', $tableIdentifier, []))];
foreach ($this->dbalSchemaTable->getForeignKeys() as $foreignKeyIdentifier => $foreignKey) {
$words = explode('_', $foreignKeyIdentifier);
$camelCased = array_map('ucfirst', $words);
$foreignKeyMethodIdentifier = join('', $camelCased);
$where = array_map(function ($methodParameter) {
return $methodParameter . ' = :' . $methodParameter;
}, $foreignKey->getLocalColumns());
$query = $this->describeQuerySelect('*', $tableIdentifier, $where);
$methods["fetchBy" . $foreignKeyMethodIdentifier] = $this->describeQueryMethod($foreignKey->getLocalColumns(), $query);
}
return ['identifier' => $namespace . $this->dbalSchemaTable->getName(), 'properties' => ['columns' => array_keys($this->dbalSchemaTable->getColumns())], 'methods' => $methods];
}
示例3: getInputs
/**
* Metodo responsavel por criar os inputs para o novo form atraves da tabela no banco de dados
* passada pelo form
*
* @return string
*/
private function getInputs()
{
$strInputs = '';
$objColumns = $this->objTable->getColumns();
foreach ($objColumns as $objColumn) {
$generatorInputFormHelper = new GeneratorInepzendFormInputHelper($objColumn, $this->isPrimaryKey($objColumn), $this->isForeignKey($objColumn));
$strInputs .= $generatorInputFormHelper->getStrCreateInputForm();
}
return $strInputs;
}
示例4: testColumns
public function testColumns()
{
$type = Type::getType('integer');
$columns = array();
$columns[] = new Column("foo", $type);
$columns[] = new Column("bar", $type);
$table = new Table("foo", $columns, array(), array());
$this->assertTrue($table->hasColumn("foo"));
$this->assertTrue($table->hasColumn("bar"));
$this->assertFalse($table->hasColumn("baz"));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Column', $table->getColumn("foo"));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Column', $table->getColumn("bar"));
$this->assertEquals(2, count($table->getColumns()));
}
示例5: getElements
/**
* Convert all the table columns into form elements
*
* @return array
* @throws \Exception
*/
public function getElements()
{
if (!$this->table instanceof Table) {
throw new \Exception('Table not set');
}
$pkColumns = $this->table->getPrimaryKey()->getColumns();
$elements = [];
$fks = [];
$fk = $this->table->getForeignKeys();
if (!empty($fk)) {
foreach ($fk as $f) {
$fks = array_merge($fks, $f->getLocalColumns());
}
}
foreach ($this->table->getColumns() as $column) {
$isPrimaryKey = in_array($column->getName(), $pkColumns);
if ($this->helper->isExcluded($column) || $isPrimaryKey) {
continue;
}
$elements[] = $this->mapColumn($column, $fks);
}
return $elements;
}
示例6: getCreateTableSQL
public function getCreateTableSQL(Table $table, array $columns, array $options = array())
{
$tableName = $table->getQuotedName($this->platform);
$sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->platform->supportsCommentOnStatement()) {
foreach ($table->getColumns() as $column) {
$comment = $this->getColumnComment($column);
if (null !== $comment && '' !== $comment) {
$sql[] = $this->platform->getCommentOnColumnSQL($tableName, $column->getQuotedName($this->platform), $comment);
}
}
}
return $sql;
}
示例7: addTable
/**
* Add a table object to the schema
*
* @param Table $table table object to add
*
* @return void
*/
public function addTable(Table $table)
{
//echo '<h2>addTable()</h2>';
try {
$name = $table->getName();
$len = strlen($this->xPrefix);
if (substr_compare($name, $this->xPrefix, 0, $len) === 0) {
$name = substr($name, $len);
if (empty($this->tableList) || in_array($name, $this->tableList)) {
$idGeneratorType = 0;
// how should we handle this?
$newtable = new Table($name, $table->getColumns(), $table->getIndexes(), $table->getForeignKeys(), $idGeneratorType, $table->getOptions());
$this->_addTable($newtable);
}
}
//Debug::dump($table);
} catch (\Exception $e) {
\Xoops::getInstance()->events()->triggerEvent('core.exception', $e);
throw $e;
}
}
示例8: saveTable
/**
* @param \Doctrine\DBAL\Schema\Table $table
* @param \SimpleXMLElement $xml
*/
private static function saveTable($table, $xml)
{
$xml->addChild('name', $table->getName());
$declaration = $xml->addChild('declaration');
foreach ($table->getColumns() as $column) {
self::saveColumn($column, $declaration->addChild('field'));
}
foreach ($table->getIndexes() as $index) {
if ($index->getName() == 'PRIMARY') {
$autoincrement = false;
foreach ($index->getColumns() as $column) {
if ($table->getColumn($column)->getAutoincrement()) {
$autoincrement = true;
}
}
if ($autoincrement) {
continue;
}
}
self::saveIndex($index, $declaration->addChild('index'));
}
}
示例9: createTableLabel
/**
* @param \Doctrine\DBAL\Schema\Table $table
*
* @return string
*/
private function createTableLabel(Table $table)
{
// Start the table
$label = '<<TABLE CELLSPACING="0" BORDER="1" ALIGN="LEFT">';
// The title
$label .= '<TR><TD BORDER="1" COLSPAN="3" ALIGN="CENTER" BGCOLOR="#fcaf3e"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">' . $table->getName() . '</FONT></TD></TR>';
// The attributes block
foreach ($table->getColumns() as $column) {
$columnLabel = $column->getName();
$label .= '<TR>';
$label .= '<TD BORDER="0" ALIGN="LEFT" BGCOLOR="#eeeeec">';
$label .= '<FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">' . $columnLabel . '</FONT>';
$label .= '</TD><TD BORDER="0" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">' . strtolower($column->getType()) . '</FONT></TD>';
$label .= '<TD BORDER="0" ALIGN="RIGHT" BGCOLOR="#eeeeec" PORT="col' . $column->getName() . '">';
if ($table->hasPrimaryKey() && in_array($column->getName(), $table->getPrimaryKey()->getColumns())) {
$label .= "✷";
}
$label .= '</TD></TR>';
}
// End the table
$label .= '</TABLE>>';
return $label;
}
示例10: diffTable
/**
* Returns the difference between the tables $table1 and $table2.
*
* If there are no differences this method returns the boolean false.
*
* @param \Doctrine\DBAL\Schema\Table $table1
* @param \Doctrine\DBAL\Schema\Table $table2
*
* @return boolean|\Doctrine\DBAL\Schema\TableDiff
*/
public function diffTable(Table $table1, Table $table2)
{
$changes = 0;
$tableDifferences = new TableDiff($table1->getName());
$tableDifferences->fromTable = $table1;
$table1Columns = $table1->getColumns();
$table2Columns = $table2->getColumns();
/* See if all the fields in table 1 exist in table 2 */
foreach ($table2Columns as $columnName => $column) {
if (!$table1->hasColumn($columnName)) {
$tableDifferences->addedColumns[$columnName] = $column;
$changes++;
}
}
/* See if there are any removed fields in table 2 */
foreach ($table1Columns as $columnName => $column) {
// See if column is removed in table 2.
if (!$table2->hasColumn($columnName)) {
$tableDifferences->removedColumns[$columnName] = $column;
$changes++;
continue;
}
// See if column has changed properties in table 2.
$changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
if (!empty($changedProperties)) {
$columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
$columnDiff->fromColumn = $column;
$tableDifferences->changedColumns[$column->getName()] = $columnDiff;
$changes++;
}
}
// #BUG-2317 Avoid column renaming when both enable and disable different modules
// $this->detectColumnRenamings($tableDifferences);
$table1Indexes = $table1->getIndexes();
$table2Indexes = $table2->getIndexes();
foreach ($table2Indexes as $index2Name => $index2Definition) {
foreach ($table1Indexes as $index1Name => $index1Definition) {
if ($this->diffIndex($index1Definition, $index2Definition) === false) {
/*if ( ! $index1Definition->isPrimary() && $index1Name != $index2Name) {
$tableDifferences->renamedIndexes[$index1Name] = $index2Definition;
$changes++;
}*/
unset($table1Indexes[$index1Name]);
unset($table2Indexes[$index2Name]);
} else {
if ($index1Name == $index2Name) {
$tableDifferences->changedIndexes[$index2Name] = $table2Indexes[$index2Name];
unset($table1Indexes[$index1Name]);
unset($table2Indexes[$index2Name]);
$changes++;
}
}
}
}
foreach ($table1Indexes as $index1Name => $index1Definition) {
$tableDifferences->removedIndexes[$index1Name] = $index1Definition;
$changes++;
}
foreach ($table2Indexes as $index2Name => $index2Definition) {
$tableDifferences->addedIndexes[$index2Name] = $index2Definition;
$changes++;
}
$fromFkeys = $table1->getForeignKeys();
$toFkeys = $table2->getForeignKeys();
foreach ($fromFkeys as $key1 => $constraint1) {
foreach ($toFkeys as $key2 => $constraint2) {
if ($this->diffForeignKey($constraint1, $constraint2) === false) {
unset($fromFkeys[$key1]);
unset($toFkeys[$key2]);
} else {
if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
$tableDifferences->changedForeignKeys[] = $constraint2;
$changes++;
unset($fromFkeys[$key1]);
unset($toFkeys[$key2]);
}
}
}
}
foreach ($fromFkeys as $constraint1) {
$tableDifferences->removedForeignKeys[] = $constraint1;
$changes++;
}
foreach ($toFkeys as $constraint2) {
$tableDifferences->addedForeignKeys[] = $constraint2;
$changes++;
}
return $changes ? $tableDifferences : false;
}
示例11: renameTableSchema
/**
* @param \Doctrine\DBAL\Schema\Table $table
* @param string $newName
* @return \Doctrine\DBAL\Schema\Table
*/
protected function renameTableSchema(Table $table, $newName)
{
/**
* @var \Doctrine\DBAL\Schema\Index[] $indexes
*/
$indexes = $table->getIndexes();
$newIndexes = array();
foreach ($indexes as $index) {
if ($index->isPrimary()) {
// do not rename primary key
$indexName = $index->getName();
} else {
// avoid conflicts in index names
$indexName = 'oc_' . \OCP\Util::generateRandomBytes(13);
}
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
}
// foreign keys are not supported so we just set it to an empty array
return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions());
}
示例12: renameTableSchema
/**
* @param \Doctrine\DBAL\Schema\Table $table
* @param string $newName
* @return \Doctrine\DBAL\Schema\Table
*/
protected function renameTableSchema(Table $table, $newName)
{
/**
* @var \Doctrine\DBAL\Schema\Index[] $indexes
*/
$indexes = $table->getIndexes();
$newIndexes = array();
foreach ($indexes as $index) {
if ($index->isPrimary()) {
// do not rename primary key
$indexName = $index->getName();
} else {
// avoid conflicts in index names
$indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
}
$newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
}
// foreign keys are not supported so we just set it to an empty array
return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions());
}
示例13: getCreateTableSQL
/**
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @param string $table The name of the table.
* @param int $createFlags
* @return array The sequence of SQL statements.
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
if (!is_int($createFlags)) {
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
}
if (count($table->getColumns()) == 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName());
}
$tableName = $table->getName();
$options = $table->getOptions();
$options['uniqueConstraints'] = array();
$options['indexes'] = array();
$options['primary'] = array();
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/* @var $index Index */
if ($index->isPrimary()) {
$options['primary'] = $index->getColumns();
} else {
$options['indexes'][$index->getName()] = $index;
}
}
}
$columns = array();
foreach ($table->getColumns() as $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */
$columnData = array();
$columnData['name'] = $column->getName();
$columnData['type'] = $column->getType();
$columnData['length'] = $column->getLength();
$columnData['notnull'] = $column->getNotNull();
$columnData['unique'] = $column->hasPlatformOption("unique") ? $column->getPlatformOption('unique') : false;
$columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255;
}
$columnData['precision'] = $column->getPrecision();
$columnData['scale'] = $column->getScale();
$columnData['default'] = $column->getDefault();
$columnData['columnDefinition'] = $column->getColumnDefinition();
if (in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true;
if ($table->isIdGeneratorIdentity()) {
$columnData['autoincrement'] = true;
}
}
$columns[$columnData['name']] = $columnData;
}
if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = array();
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
}
}
return $this->_getCreateTableSQL($tableName, $columns, $options);
}
示例14: _generateModel
/**
* @param \Doctrine\DBAL\Schema\Table $table
*
* @return bool|int
* @todo convert to Blade stub
*/
protected function _generateModel(Table $table)
{
$_props = [];
$_name = $table->getName();
$_modelName = $this->_getModelName($_name);
try {
foreach ($table->getColumns() as $_column) {
$_type = $_column->getType()->getName();
$_type == 'datetime' && ($_type = 'Carbon');
$_props[] = ' * @property ' . $_type . ' $' . $_column->getName();
}
$_payload = ['tableName' => $_name, 'modelName' => $_modelName, 'namespace' => $this->option('namespace') ?: 'App\\Models', 'props' => $_props];
$_filename = $this->destination . DIRECTORY_SEPARATOR . $_modelName . '.php';
$_props = implode(PHP_EOL, $_props);
$_php = <<<TEXT
<?php namespace {$_payload['namespace']};
use Carbon\\Carbon;
use Illuminate\\Database\\Eloquent\\Model;
/**
{$_props}
*/
class {$_payload['modelName']} extends Model
{
//******************************************************************************
//* Members
//******************************************************************************
protected \$table = '{$_payload['tableName']}';
}
TEXT;
return file_put_contents($_filename, $_php);
} catch (\Exception $_ex) {
$this->_writeln(' * error examining table "' . $_name . '": ' . $_ex->getMessage());
return false;
}
}
示例15: getCreateTableSQL
/**
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @param string $table The name of the table.
* @param int $createFlags
* @return array The sequence of SQL statements.
*/
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{
if (!is_int($createFlags)) {
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
}
if (count($table->getColumns()) == 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName());
}
$tableName = $table->getQuotedName($this);
$options = $table->getOptions();
$options['uniqueConstraints'] = array();
$options['indexes'] = array();
$options['primary'] = array();
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/* @var $index Index */
if ($index->isPrimary()) {
$options['primary'] = $index->getColumns();
} else {
$options['indexes'][$index->getName()] = $index;
}
}
}
$columnSql = array();
$columns = array();
foreach ($table->getColumns() as $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
$eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
if ($eventArgs->isDefaultPrevented()) {
continue;
}
}
$columnData = array();
$columnData['name'] = $column->getQuotedName($this);
$columnData['type'] = $column->getType();
$columnData['length'] = $column->getLength();
$columnData['notnull'] = $column->getNotNull();
$columnData['fixed'] = $column->getFixed();
$columnData['unique'] = false;
// TODO: what do we do about this?
$columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255;
}
$columnData['unsigned'] = $column->getUnsigned();
$columnData['precision'] = $column->getPrecision();
$columnData['scale'] = $column->getScale();
$columnData['default'] = $column->getDefault();
$columnData['columnDefinition'] = $column->getColumnDefinition();
$columnData['autoincrement'] = $column->getAutoincrement();
$columnData['comment'] = $this->getColumnComment($column);
if (in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true;
}
$columns[$columnData['name']] = $columnData;
}
if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = array();
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
}
}
if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
$eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
if ($eventArgs->isDefaultPrevented()) {
return array_merge($eventArgs->getSql(), $columnSql);
}
}
$sql = $this->_getCreateTableSQL($tableName, $columns, $options);
if ($this->supportsCommentOnStatement()) {
foreach ($table->getColumns() as $column) {
if ($this->getColumnComment($column)) {
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
}
}
}
return array_merge($sql, $columnSql);
}