本文整理汇总了PHP中Propel\Generator\Model\Index类的典型用法代码示例。如果您正苦于以下问题:PHP Index类的具体用法?PHP Index怎么用?PHP Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCompareDifferentOrder
public function testCompareDifferentOrder()
{
$c1 = new Column('Foo');
$c2 = new Column('Bar');
$i1 = new Index('Foo_Bar_Index');
$i1->addColumn($c1);
$i1->addColumn($c2);
$c3 = new Column('Foo');
$c4 = new Column('Bar');
$i2 = new Index('Foo_Bar_Index');
$i2->addColumn($c4);
$i2->addColumn($c3);
$this->assertTrue(IndexComparator::computeDiff($i1, $i2));
}
示例2: addArchiveTable
protected function addArchiveTable()
{
$table = $this->getTable();
$database = $table->getDatabase();
$archiveTableName = $this->getParameter('archive_table') ? $this->getParameter('archive_table') : $this->getTable()->getName() . '_archive';
if (!$database->hasTable($archiveTableName)) {
// create the version table
$archiveTable = $database->addTable(array('name' => $archiveTableName, 'package' => $table->getPackage(), 'schema' => $table->getSchema(), 'namespace' => $table->getNamespace() ? '\\' . $table->getNamespace() : null));
$archiveTable->isArchiveTable = true;
// copy all the columns
foreach ($table->getColumns() as $column) {
$columnInArchiveTable = clone $column;
if ($columnInArchiveTable->hasReferrers()) {
$columnInArchiveTable->clearReferrers();
}
if ($columnInArchiveTable->isAutoincrement()) {
$columnInArchiveTable->setAutoIncrement(false);
}
$archiveTable->addColumn($columnInArchiveTable);
}
// add archived_at column
if ($this->getParameter('log_archived_at') == 'true') {
$archiveTable->addColumn(array('name' => $this->getParameter('archived_at_column'), 'type' => 'TIMESTAMP'));
}
// do not copy foreign keys
// copy the indices
foreach ($table->getIndices() as $index) {
$copiedIndex = clone $index;
$copiedIndex->setName('');
$archiveTable->addIndex($copiedIndex);
}
// copy unique indices to indices
// see https://github.com/propelorm/Propel/issues/175 for details
foreach ($table->getUnices() as $unique) {
$index = new Index();
foreach ($unique->getColumns() as $columnName) {
if ($size = $unique->getColumnSize($columnName)) {
$index->addColumn(array('name' => $columnName, 'size' => $size));
} else {
$index->addColumn(array('name' => $columnName));
}
}
$archiveTable->addIndex($index);
}
// every behavior adding a table should re-execute database behaviors
foreach ($database->getBehaviors() as $behavior) {
$behavior->modifyDatabase();
}
$this->archiveTable = $archiveTable;
} else {
$this->archiveTable = $database->getTable($archiveTableName);
}
}
示例3: computeDiff
/**
* Computes the difference between two index objects.
*
* @param Index $fromIndex
* @param Index $toIndex
* @param boolean $caseInsensitive
* @return boolean
*/
public static function computeDiff(Index $fromIndex, Index $toIndex, $caseInsensitive = false)
{
// Check for removed index columns in $toIndex
$fromIndexColumns = $fromIndex->getColumns();
$max = count($fromIndexColumns);
for ($i = 0; $i < $max; $i++) {
$indexColumn = $fromIndexColumns[$i];
if (!$toIndex->hasColumnAtPosition($i, $indexColumn, $fromIndex->getColumnSize($indexColumn), $caseInsensitive)) {
return true;
}
}
// Check for new index columns in $toIndex
$toIndexColumns = $toIndex->getColumns();
$max = count($toIndexColumns);
for ($i = 0; $i < $max; $i++) {
$indexColumn = $toIndexColumns[$i];
if (!$fromIndex->hasColumnAtPosition($i, $indexColumn, $toIndex->getColumnSize($indexColumn), $caseInsensitive)) {
return true;
}
}
// Check for difference in unicity
return $fromIndex->isUnique() !== $toIndex->isUnique();
}
示例4: ForeignKey
$fkCategoryPost->setDefaultJoin('Criteria::INNER_JOIN');
$fkCategoryPost->setOnDelete('SETNULL');
$fkPostTag = new ForeignKey('fk_post_has_tags');
$fkPostTag->addReference('post_id', 'id');
$fkPostTag->setForeignTableCommonName('blog_post');
$fkPostTag->setPhpName('Post');
$fkPostTag->setDefaultJoin('Criteria::LEFT_JOIN');
$fkPostTag->setOnDelete('CASCADE');
$fkTagPost = new ForeignKey('fk_tag_has_posts');
$fkTagPost->addReference('tag_id', 'id');
$fkTagPost->setForeignTableCommonName('blog_tag');
$fkTagPost->setPhpName('Tag');
$fkTagPost->setDefaultJoin('Criteria::LEFT_JOIN');
$fkTagPost->setOnDelete('CASCADE');
/* Regular Indexes */
$pageContentFulltextIdx = new Index('page_content_fulltext_idx');
$pageContentFulltextIdx->setColumns([['name' => 'content']]);
$pageContentFulltextIdx->addVendorInfo(new VendorInfo('mysql', ['Index_type' => 'FULLTEXT']));
/* Unique Indexes */
$authorUsernameUnique = new Unique('author_password_unique_idx');
$authorUsernameUnique->setColumns([['name' => 'username', 'size' => '8']]);
/* Behaviors */
$timestampableBehavior = new TimestampableBehavior();
$timestampableBehavior->setName('timestampable');
$sluggableBehavior = new SluggableBehavior();
$sluggableBehavior->setName('sluggable');
/* Tables */
$table1 = new Table('blog_post');
$table1->setDescription('The list of posts');
$table1->setNamespace('Blog');
$table1->setPackage('Acme.Blog');
示例5: addIndex
/**
* Adds a new index to the indices list and set the
* parent table of the column to the current table.
*
* @param Index|array $index
* @return Index
*
* @throw InvalidArgumentException
*/
public function addIndex($index)
{
if ($index instanceof Index) {
if ($this->hasIndex($index->getName())) {
throw new InvalidArgumentException(sprintf('Index "%s" already exist.', $index->getName()));
}
if (!$index->getColumns()) {
throw new InvalidArgumentException(sprintf('Index "%s" has no columns.', $index->getName()));
}
$index->setTable($this);
// force the name to be created if empty.
$this->indices[] = $index;
return $index;
}
$idx = new Index();
$idx->loadMapping($index);
foreach ((array) @$index['columns'] as $column) {
$idx->addColumn($column);
}
return $this->addIndex($idx);
}
示例6: getAddIndexDDL
/**
* Builds the DDL SQL to add an Index.
*
* @param Index $index
* @return string
*/
public function getAddIndexDDL(Index $index)
{
// don't create index form primary key
if ($this->getPrimaryKeyName($index->getTable()) == $this->quoteIdentifier($index->getName())) {
return '';
}
$pattern = "\nCREATE %sINDEX %s ON %s (%s)%s;\n";
return sprintf($pattern, $index->isUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->quoteIdentifier($index->getTable()->getName()), $this->getColumnListDDL($index->getColumnObjects()), $this->generateBlockStorage($index));
}
示例7: testIsIndex
public function testIsIndex()
{
$table = new Table();
$column1 = new Column('category_id');
$column2 = new Column('type');
$table->addColumn($column1);
$table->addColumn($column2);
$index = new Index('test_index');
$index->setColumns([$column1, $column2]);
$table->addIndex($index);
$this->assertTrue($table->isIndex(['category_id', 'type']));
$this->assertTrue($table->isIndex(['type', 'category_id']));
$this->assertFalse($table->isIndex(['category_id', 'type2']));
$this->assertFalse($table->isIndex(['asd']));
}
示例8: getDropIndexDDL
/**
* Overrides the implementation from DefaultPlatform
*
* @author Niklas Närhinen <niklas@narhinen.net>
* @return string
* @see DefaultPlatform::getDropIndexDDL
*/
public function getDropIndexDDL(Index $index)
{
if ($index instanceof Unique) {
$pattern = "\n ALTER TABLE %s DROP CONSTRAINT %s;\n ";
return sprintf($pattern, $this->quoteIdentifier($index->getTable()->getName()), $this->quoteIdentifier($index->getName()));
} else {
return parent::getDropIndexDDL($index);
}
}
示例9: addSnapshotTable
private function addSnapshotTable()
{
$table = $this->getTable();
$primaryKeyColumn = $table->getFirstPrimaryKeyColumn();
$database = $table->getDatabase();
$snapshotTableName = $this->getParameter(self::PARAMETER_SNAPSHOT_TABLE) ?: $this->getDefaultSnapshotTableName();
if ($database->hasTable($snapshotTableName)) {
$this->snapshotTable = $database->getTable($snapshotTableName);
return;
}
$snapshotTable = $database->addTable(['name' => $snapshotTableName, 'phpName' => $this->getParameter(self::PARAMETER_SNAPSHOT_PHPNAME), 'package' => $table->getPackage(), 'schema' => $table->getSchema(), 'namespace' => $table->getNamespace() ? '\\' . $table->getNamespace() : null]);
$addSnapshotAt = true;
$hasTimestampableBehavior = 0 < count(array_filter($database->getBehaviors(), function (Behavior $behavior) {
return 'timestampable' === $behavior->getName();
}));
if ($hasTimestampableBehavior) {
$addSnapshotAt = false;
$timestampableBehavior = clone $database->getBehavior('timestampable');
$timestampableBehavior->setParameters(array_merge($timestampableBehavior->getParameters(), ['create_column' => $this->getParameter(self::PARAMETER_SNAPSHOT_AT_COLUMN), 'disable_updated_at' => 'true']));
$snapshotTable->addBehavior($timestampableBehavior);
}
$snapshotTable->isSnapshotTable = true;
$idColumn = $snapshotTable->addColumn(['name' => 'id', 'type' => 'INTEGER']);
$idColumn->setAutoIncrement(true);
$idColumn->setPrimaryKey(true);
$idColumn->setNotNull(true);
$columns = $table->getColumns();
foreach ($columns as $column) {
if ($column->isPrimaryKey()) {
continue;
}
$columnInSnapshotTable = clone $column;
$columnInSnapshotTable->setNotNull(false);
if ($columnInSnapshotTable->hasReferrers()) {
$columnInSnapshotTable->clearReferrers();
}
if ($columnInSnapshotTable->isAutoincrement()) {
$columnInSnapshotTable->setAutoIncrement(false);
}
$snapshotTable->addColumn($columnInSnapshotTable);
}
$foreignKeyColumn = $snapshotTable->addColumn(['name' => $this->getParameter(self::PARAMETER_REFERENCE_COLUMN), 'type' => $primaryKeyColumn->getType(), 'size' => $primaryKeyColumn->getSize()]);
$index = new Index();
$index->setName($this->getParameter(self::PARAMETER_REFERENCE_COLUMN));
if ($primaryKeyColumn->getSize()) {
$index->addColumn(['name' => $this->getParameter(self::PARAMETER_REFERENCE_COLUMN), 'size' => $primaryKeyColumn->getSize()]);
} else {
$index->addColumn(['name' => $this->getParameter(self::PARAMETER_REFERENCE_COLUMN)]);
}
$snapshotTable->addIndex($index);
$foreignKey = new ForeignKey();
$foreignKey->setName(vsprintf('fk_%s_%s', [$snapshotTable->getOriginCommonName(), $this->getParameter(self::PARAMETER_REFERENCE_COLUMN)]));
$foreignKey->setOnUpdate('CASCADE');
$foreignKey->setOnDelete('SET NULL');
$foreignKey->setForeignTableCommonName($this->getTable()->getCommonName());
$foreignKey->addReference($foreignKeyColumn, $primaryKeyColumn);
$snapshotTable->addForeignKey($foreignKey);
if ($this->getParameter(self::PARAMETER_LOG_SNAPSHOT_AT) == 'true' && $addSnapshotAt) {
$snapshotTable->addColumn(['name' => $this->getParameter(self::PARAMETER_SNAPSHOT_AT_COLUMN), 'type' => 'TIMESTAMP']);
}
$indices = $table->getIndices();
foreach ($indices as $index) {
$copiedIndex = clone $index;
$snapshotTable->addIndex($copiedIndex);
}
// copy unique indices to indices
// see https://github.com/propelorm/Propel/issues/175 for details
$unices = $table->getUnices();
foreach ($unices as $unique) {
$index = new Index();
$index->setName($unique->getName());
$columns = $unique->getColumns();
foreach ($columns as $columnName) {
if ($size = $unique->getColumnSize($columnName)) {
$index->addColumn(['name' => $columnName, 'size' => $size]);
} else {
$index->addColumn(['name' => $columnName]);
}
}
$snapshotTable->addIndex($index);
}
$behaviors = $database->getBehaviors();
foreach ($behaviors as $behavior) {
$behavior->modifyDatabase();
}
$this->snapshotTable = $snapshotTable;
}
示例10: providerForTestGetIndexDDL
public function providerForTestGetIndexDDL()
{
$table = new Table('foo');
$table->setIdentifierQuoting(true);
$column1 = new Column('bar1');
$column1->getDomain()->copy(new Domain('FOOTYPE'));
$table->addColumn($column1);
$column2 = new Column('bar2');
$column2->getDomain()->copy(new Domain('BARTYPE'));
$table->addColumn($column2);
$index = new Index('babar');
$index->addColumn($column1);
$index->addColumn($column2);
$table->addIndex($index);
return array(array($index));
}
示例11: testHasColumnAtFirstPosition
public function testHasColumnAtFirstPosition()
{
$index = new Index();
$index->addColumn($this->getColumnMock('foo', array('size' => 0)));
$this->assertTrue($index->hasColumnAtPosition(0, 'foo'));
}
示例12: startElement
public function startElement($parser, $name, $attributes)
{
$parentTag = $this->peekCurrentSchemaTag();
if (false === $parentTag) {
switch ($name) {
case 'database':
if ($this->isExternalSchema()) {
$this->currentPackage = isset($attributes['package']) ? $attributes['package'] : null;
if (null === $this->currentPackage) {
$this->currentPackage = $this->defaultPackage;
}
} else {
$this->currDB = $this->schema->addDatabase($attributes);
}
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
} elseif ('database' === $parentTag) {
switch ($name) {
case 'external-schema':
$xmlFile = isset($attributes['filename']) ? $attributes['filename'] : null;
// 'referenceOnly' attribute is valid in the main schema XML file only,
// and it's ignored in the nested external-schemas
if (!$this->isExternalSchema()) {
$isForRefOnly = isset($attributes['referenceOnly']) ? $attributes['referenceOnly'] : null;
$this->isForReferenceOnly = null !== $isForRefOnly ? 'true' === strtolower($isForRefOnly) : true;
// defaults to TRUE
}
if ('/' !== $xmlFile[0]) {
$xmlFile = realpath(dirname($this->currentXmlFile) . DIRECTORY_SEPARATOR . $xmlFile);
if (!file_exists($xmlFile)) {
throw new SchemaException(sprintf('Unknown include external "%s"', $xmlFile));
}
}
$this->parseFile($xmlFile);
break;
case 'domain':
$this->currDB->addDomain($attributes);
break;
case 'table':
if (!isset($attributes['schema']) && $this->currDB->getSchema() && $this->currDB->getPlatform()->supportsSchemas() && false === strpos($attributes['name'], $this->currDB->getPlatform()->getSchemaDelimiter())) {
$attributes['schema'] = $this->currDB->getSchema();
}
$this->currTable = $this->currDB->addTable($attributes);
if ($this->isExternalSchema()) {
$this->currTable->setForReferenceOnly($this->isForReferenceOnly);
$this->currTable->setPackage($this->currentPackage);
}
break;
case 'vendor':
$this->currVendorObject = $this->currDB->addVendorInfo($attributes);
break;
case 'behavior':
$this->currBehavior = $this->currDB->addBehavior($attributes);
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
} elseif ('table' === $parentTag) {
switch ($name) {
case 'column':
$this->currColumn = $this->currTable->addColumn($attributes);
break;
case 'foreign-key':
$this->currFK = $this->currTable->addForeignKey($attributes);
break;
case 'index':
$this->currIndex = new Index();
$this->currIndex->setTable($this->currTable);
$this->currIndex->loadMapping($attributes);
break;
case 'unique':
$this->currUnique = new Unique();
$this->currUnique->setTable($this->currTable);
$this->currUnique->loadMapping($attributes);
break;
case 'vendor':
$this->currVendorObject = $this->currTable->addVendorInfo($attributes);
break;
case 'id-method-parameter':
$this->currTable->addIdMethodParameter($attributes);
break;
case 'behavior':
$this->currBehavior = $this->currTable->addBehavior($attributes);
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
} elseif ('column' === $parentTag) {
switch ($name) {
case 'inheritance':
$this->currColumn->addInheritance($attributes);
break;
case 'vendor':
$this->currVendorObject = $this->currColumn->addVendorInfo($attributes);
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
//.........这里部分代码省略.........
示例13: addColumn
protected function addColumn(Table $table, $name)
{
if (!$table->hasColumn($name)) {
$column = new Column($name);
// don't know how to define unsigned :(
$domain = new Domain('TINYINT', 'tinyint(3) unsigned');
$column->setDomain($domain);
$table->addColumn($column);
$column_idx_name = $name . '_idx';
if (!$table->hasIndex($column_idx_name)) {
$column_idx = new Index($column_idx_name);
$column_idx->addColumn(['name' => $column->getName()]);
$table->addIndex($column_idx);
}
}
}
示例14: getIndexDDL
/**
* Builds the DDL SQL for an Index object.
*
* @param Index $index
* @return string
*/
public function getIndexDDL(Index $index)
{
return sprintf('%sINDEX %s (%s)', $index->isUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->getColumnListDDL($index->getColumnObjects()));
}
示例15: testCompareModifiedIndices
public function testCompareModifiedIndices()
{
$t1 = new Table();
$c1 = new Column('Foo');
$c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
$c1->getDomain()->replaceSize(255);
$c1->setNotNull(false);
$t1->addColumn($c1);
$i1 = new Index('Foo_Index');
$i1->addColumn($c1);
$t1->addIndex($i1);
$t2 = new Table();
$c2 = new Column('Foo');
$c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
$c2->getDomain()->replaceScale(2);
$c2->getDomain()->replaceSize(3);
$c2->setNotNull(true);
$c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
$t2->addColumn($c2);
$i2 = new Unique('Foo_Index');
$i2->addColumn($c2);
$t2->addIndex($i2);
$tc = new PropelTableComparator();
$tc->setFromTable($t1);
$tc->setToTable($t2);
$nbDiffs = $tc->compareIndices();
$tableDiff = $tc->getTableDiff();
$this->assertEquals(1, $nbDiffs);
$this->assertEquals(1, count($tableDiff->getModifiedIndices()));
$this->assertEquals(array('Foo_Index' => array($i1, $i2)), $tableDiff->getModifiedIndices());
}