当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::getIndexes方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Schema\Table::getIndexes方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::getIndexes方法的具体用法?PHP Table::getIndexes怎么用?PHP Table::getIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Schema\Table的用法示例。


在下文中一共展示了Table::getIndexes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testEncodedUniqueIndexNameIsTheSameAsDoctrineDefault

 public function testEncodedUniqueIndexNameIsTheSameAsDoctrineDefault()
 {
     $tableName = 'tbl123456789012345';
     $columnName = 'clmn1234567890';
     $table = new Table($tableName, [new Column($columnName, Type::getType('string'))]);
     $table->addUniqueIndex([$columnName]);
     $indices = $table->getIndexes();
     $doctrineResult = array_pop($indices)->getName();
     $generator = new DbIdentifierNameGenerator();
     $result = $generator->generateIndexName($tableName, [$columnName], true);
     $this->assertEquals($doctrineResult, $result);
 }
开发者ID:Maksold,项目名称:platform,代码行数:12,代码来源:DbIdentifierNameGeneratorTest.php

示例2: analyzeIndexes

 private function analyzeIndexes()
 {
     $indexes = $this->table->getIndexes();
     $this->uniqueFields = [];
     foreach ($indexes as $index) {
         if ($index->isPrimary()) {
             $columns = $index->getColumns();
             if (sizeof($columns) == 1) {
                 $this->primaryKey = $columns[0];
             }
         }
         if ($index->isUnique()) {
             $columns = $index->getColumns();
             if (sizeof($columns) == 1) {
                 $column = $columns[0];
                 if ($column != $this->primaryKey) {
                     $this->uniqueFields[] = $column;
                 }
             }
         }
     }
 }
开发者ID:jonphipps,项目名称:laravel-api-test,代码行数:22,代码来源:TableFieldsGenerator.php

示例3: 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;
     }
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:28,代码来源:PrefixStripper.php

示例4: 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'));
     }
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:26,代码来源:MDB2SchemaWriter.php

示例5: 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;
 }
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:99,代码来源:Comparator.php

示例6: 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());
 }
开发者ID:drognisep,项目名称:Portfolio-Site,代码行数:25,代码来源:Migrator.php

示例7: getClusteredIndex

 /**
  * @param \Doctrine\DBAL\Schema\Table $table
  *
  * @return \Doctrine\DBAL\Schema\Index
  *
  * @throws \RuntimeException
  */
 private function getClusteredIndex($table)
 {
     foreach ($table->getIndexes() as $index) {
         if ($index->isPrimary() && !$index->hasFlag('nonclustered')) {
             return $index;
         } elseif ($index->hasFlag('clustered')) {
             return $index;
         }
     }
     throw new \RuntimeException("No clustered index found on table " . $table->getName());
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:18,代码来源:MultiTenantVisitor.php

示例8: isColumnUnique

 /**
  * @param Table $table
  * @param string $column
  * @return bool
  */
 protected function isColumnUnique(Table $table, $column)
 {
     foreach ($table->getIndexes() as $index) {
         $indexColumns = $index->getColumns();
         if (count($indexColumns) !== 1) {
             continue;
         }
         $indexColumn = $indexColumns[0];
         if ($indexColumn === $column && $index->isUnique()) {
             return true;
         }
     }
     return false;
 }
开发者ID:xvlady,项目名称:eloquent-model-generator,代码行数:19,代码来源:EloquentModelBuilder.php

示例9: 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);
 }
开发者ID:skoop,项目名称:doctrine2,代码行数:64,代码来源:AbstractPlatform.php

示例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++;
         }
     }
     $this->detectColumnRenamings($tableDifferences);
     $table1Indexes = $table1->getIndexes();
     $table2Indexes = $table2->getIndexes();
     /* See if all the indexes in table 1 exist in table 2 */
     foreach ($table2Indexes as $indexName => $index) {
         if ($index->isPrimary() && $table1->hasPrimaryKey() || $table1->hasIndex($indexName)) {
             continue;
         }
         $tableDifferences->addedIndexes[$indexName] = $index;
         $changes++;
     }
     /* See if there are any removed indexes in table 2 */
     foreach ($table1Indexes as $indexName => $index) {
         // See if index is removed in table 2.
         if ($index->isPrimary() && !$table2->hasPrimaryKey() || !$index->isPrimary() && !$table2->hasIndex($indexName)) {
             $tableDifferences->removedIndexes[$indexName] = $index;
             $changes++;
             continue;
         }
         // See if index has changed in table 2.
         $table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName);
         if ($this->diffIndex($index, $table2Index)) {
             $tableDifferences->changedIndexes[$indexName] = $table2Index;
             $changes++;
         }
     }
     $this->detectIndexRenamings($tableDifferences);
     $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;
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:95,代码来源:Comparator.php

示例11: testOverruleIndex

 /**
  * @group DBAL-50
  */
 public function testOverruleIndex()
 {
     $table = new Table("bar");
     $table->addColumn('baz', 'integer', array());
     $table->addIndex(array('baz'));
     $indexes = $table->getIndexes();
     $this->assertEquals(1, count($indexes));
     $index = current($indexes);
     $table->addUniqueIndex(array('baz'));
     $this->assertEquals(1, count($table->getIndexes()));
     $this->assertFalse($table->hasIndex($index->getName()));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:15,代码来源:TableTest.php

示例12: testPrimaryKeyOverrulesUniqueIndex

 public function testPrimaryKeyOverrulesUniqueIndex()
 {
     $table = new Table("bar");
     $table->addColumn('baz', 'integer', array());
     $table->addUniqueIndex(array('baz'));
     $table->setPrimaryKey(array('baz'));
     $indexes = $table->getIndexes();
     $this->assertEquals(1, count($indexes), "Table should only contain the primary key table index, not the unique one anymore, because it was overruled.");
     $index = current($indexes);
     $this->assertTrue($index->isPrimary());
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:11,代码来源:TableTest.php

示例13: Table

 public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyConstraintIndexWithSameNameDoesNotThrowException()
 {
     $foreignTable = new Table('foreign');
     $foreignTable->addColumn('id', 'integer');
     $localTable = new Table('local');
     $localTable->addColumn('id', 'integer');
     $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id'));
     $this->assertCount(1, $localTable->getIndexes());
     $this->assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750'));
     $implicitIndex = $localTable->getIndex('IDX_8BD688E8BF396750');
     $localTable->addIndex(array('id'), 'IDX_8BD688E8BF396750');
     $this->assertCount(1, $localTable->getIndexes());
     $this->assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750'));
     $this->assertNotSame($implicitIndex, $localTable->getIndex('IDX_8BD688E8BF396750'));
 }
开发者ID:selimcr,项目名称:servigases,代码行数:15,代码来源:TableTest.php

示例14: unique

 /**
  * Assert that the column has a unique index.
  *
  * @return $this
  */
 public function unique()
 {
     $this->assertUniqueIndex($this->getIndexName('unique'), $this->table->getIndexes());
 }
开发者ID:erikgall,项目名称:eloquent-phpunit,代码行数:9,代码来源:Column.php

示例15: getCreateTableSQL

 /**
  * {@inheritDoc}
  * Gets the SQL statement(s) to create a table with the specified name, columns and constraints
  * on this platform.
  *
  * @param Table $table The name of the table.
  * @param integer $createFlags
  *
  * @return array The sequence of SQL statements.
  */
 public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
 {
     if (!is_int($createFlags)) {
         $msg = "Second argument of CratePlatform::getCreateTableSQL() has to be integer.";
         throw new \InvalidArgumentException($msg);
     }
     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()) {
                 $platform = $this;
                 $options['primary'] = array_map(function ($columnName) use($table, $platform) {
                     return $table->getColumn($columnName)->getQuotedName($platform);
                 }, $index->getColumns());
                 $options['primary_index'] = $index;
             } else {
                 $options['indexes'][$index->getName()] = $index;
             }
         }
     }
     $columnSql = array();
     $columns = array();
     foreach ($table->getColumns() as $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;
             }
         }
         $columns[$column->getQuotedName($this)] = $this->prepareColumnData($column, $options['primary']);
     }
     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);
 }
开发者ID:crate,项目名称:crate-dbal,代码行数:68,代码来源:CratePlatform.php


注:本文中的Doctrine\DBAL\Schema\Table::getIndexes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。