Table PHP Class Code Examples

This page contains top rated real world PHP examples of class Table extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: PropelTableForeignKeyComparatorTest.php Project: disider/Propel2
0
 public function testCompareModifiedFks()
 {
     $db1 = new Database();
     $db1->setPlatform($this->platform);
     $c1 = new Column('Foo');
     $c2 = new Column('Bar');
     $fk1 = new ForeignKey('my_foreign_key');
     $fk1->addReference($c1, $c2);
     $t1 = new Table('Baz');
     $t1->addForeignKey($fk1);
     $db1->addTable($t1);
     $db2 = new Database();
     $db2->setPlatform($this->platform);
     $c3 = new Column('Foo');
     $c4 = new Column('Bar2');
     $fk2 = new ForeignKey('my_foreign_key');
     $fk2->addReference($c3, $c4);
     $t2 = new Table('Baz');
     $t2->addForeignKey($fk2);
     $db2->addTable($t2);
     $tc = new TableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareForeignKeys();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedFks()));
     $this->assertEquals(['my_foreign_key' => [$fk1, $fk2]], $tableDiff->getModifiedFks());
 }
Example #2
Show file File: PlatformTestProvider.php Project: kalaspuffar/php-orm-benchmark
0
 public function providerForTestGetForeignKeysDDL()
 {
     $table1 = new Table('foo');
     $column1 = new Column('bar_id');
     $column1->getDomain()->copy(new Domain('FOOTYPE'));
     $table1->addColumn($column1);
     $table2 = new Table('bar');
     $column2 = new Column('id');
     $column2->getDomain()->copy(new Domain('BARTYPE'));
     $table2->addColumn($column2);
     $fk = new ForeignKey('foo_bar_FK');
     $fk->setForeignTableCommonName('bar');
     $fk->addReference($column1, $column2);
     $fk->setOnDelete('CASCADE');
     $table1->addForeignKey($fk);
     $column3 = new Column('baz_id');
     $column3->getDomain()->copy(new Domain('BAZTYPE'));
     $table1->addColumn($column3);
     $table3 = new Table('baz');
     $column4 = new Column('id');
     $column4->getDomain()->copy(new Domain('BAZTYPE'));
     $table3->addColumn($column4);
     $fk = new ForeignKey('foo_baz_FK');
     $fk->setForeignTableCommonName('baz');
     $fk->addReference($column3, $column4);
     $fk->setOnDelete('SETNULL');
     $table1->addForeignKey($fk);
     return array(array($table1));
 }
Example #3
Show file File: PropelDotGeneratorTest.php Project: kalaspuffar/php-orm-benchmark
0
 public function testColumnIsFKAndPK()
 {
     $column = new Column();
     $column->setName('id');
     $column->setPrimaryKey(true);
     $column->setAutoIncrement(true);
     $column->setType('integer');
     $table = new Table();
     $table->setCommonName('table_one');
     $table->addColumn($column);
     $db = new Database();
     $db->setName('MultipleTables');
     $db->addTable($table);
     $column = new Column();
     $column->setName('id');
     $column->setPrimaryKey(true);
     $column->setAutoIncrement(true);
     $column->setType('integer');
     $c2 = new Column();
     $c2->setPrimaryKey(true);
     $c2->setName('foreign_id');
     $c2->setType('integer');
     $table = new Table();
     $table->setCommonName('table_two');
     $table->addColumn($column);
     $table->addColumn($c2);
     $fk = new ForeignKey();
     $fk->setName('FK_1');
     $fk->addReference('foreign_id', 'id');
     $fk->setForeignTableCommonName('table_one');
     $table->addForeignKey($fk);
     $db->addTable($table);
     $expected = implode("\n", array('digraph G {', '"table_one" [label="{<table>table_one|<cols>id (integer) [PK]\\l}", shape=record];', '"table_two" [label="{<table>table_two|<cols>id (integer) [PK]\\lforeign_id (integer) [FK] [PK]\\l}", shape=record];', '"table_two":cols -> "table_one":table [label="foreign_id=id"];', '}', ''));
     $this->assertEquals($expected, PropelDotGenerator::create($db));
 }
Example #4
Show file File: PropelTableIndexComparatorTest.php Project: dracony/forked-php-orm-benchmark
0
 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 TableComparator();
     $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());
 }
Example #5
Show file File: PlatformTestProvider.php Project: dracony/forked-php-orm-benchmark
0
 public function providerForTestGetForeignKeysDDL()
 {
     $db = new Database();
     $db->setIdentifierQuoting(true);
     $table1 = new Table('foo');
     $db->addTable($table1);
     $column1 = new Column('bar_id');
     $column1->getDomain()->copy(new Domain('FOOTYPE'));
     $table1->addColumn($column1);
     $table2 = new Table('bar');
     $db->addTable($table2);
     $column2 = new Column('id');
     $column2->getDomain()->copy(new Domain('BARTYPE'));
     $table2->addColumn($column2);
     $fk = new ForeignKey('foo_bar_fk');
     $fk->setForeignTableCommonName('bar');
     $fk->addReference($column1, $column2);
     $fk->setOnDelete('CASCADE');
     $table1->addForeignKey($fk);
     $column3 = new Column('baz_id');
     $column3->getDomain()->copy(new Domain('BAZTYPE'));
     $table1->addColumn($column3);
     $table3 = new Table('baz');
     $db->addTable($table3);
     $column4 = new Column('id');
     $column4->getDomain()->copy(new Domain('BAZTYPE'));
     $table3->addColumn($column4);
     $fk = new ForeignKey('foo_baz_fk');
     $fk->setForeignTableCommonName('baz');
     $fk->addReference($column3, $column4);
     $fk->setOnDelete('SETNULL');
     $table1->addForeignKey($fk);
     return array(array($table1));
 }
Example #6
Show file File: PropelTableForeignKeyComparatorTest.php Project: kalaspuffar/php-orm-benchmark
0
 public function testCompareModifiedFks()
 {
     $db1 = new Database();
     $db1->setPlatform($this->platform);
     $c1 = new Column('Foo');
     $c2 = new Column('Bar');
     $fk1 = new ForeignKey();
     $fk1->addReference($c1, $c2);
     $t1 = new Table('Baz');
     $t1->addForeignKey($fk1);
     $db1->addTable($t1);
     $t1->doNaming();
     $db2 = new Database();
     $db2->setPlatform($this->platform);
     $c3 = new Column('Foo');
     $c4 = new Column('Bar2');
     $fk2 = new ForeignKey();
     $fk2->addReference($c3, $c4);
     $t2 = new Table('Baz');
     $t2->addForeignKey($fk2);
     $db2->addTable($t2);
     $t2->doNaming();
     $tc = new TableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareForeignKeys();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedFks()));
     $this->assertEquals(array('Baz_FK_1' => array($fk1, $fk2)), $tableDiff->getModifiedFks());
 }
Example #7
Show file File: HodnoteniaCallback.php Project: BGCX067/fajr-svn-to-git
0
 public function getHtml()
 {
     $trace = $this->trace->addChild("HodnoteniaCallback");
     $hodnotenia = $this->app->getHodnotenia($trace);
     $hodnoteniaTable = new Table(TableDefinitions::hodnotenia());
     $priemeryCalculator = new PriemeryCalculator();
     foreach (Sorter::sort($hodnotenia->getData(), array("semester" => -1, "nazov" => 1)) as $row) {
         if ($row['semester'] == 'L') {
             $class = 'leto';
             $priemeryCalculator->add(PriemeryCalculator::SEMESTER_LETNY, $row['znamka'], $row['kredit']);
         } else {
             $class = 'zima';
             $priemeryCalculator->add(PriemeryCalculator::SEMESTER_ZIMNY, $row['znamka'], $row['kredit']);
         }
         $hodnoteniaTable->addRow($row, array('class' => $class));
     }
     $hodnoteniaCollapsible = new Collapsible(new HtmlHeader('Hodnotenia'), $hodnoteniaTable);
     $priemery = $this->app->getPriemery($trace);
     $priemeryTable = new Table(TableDefinitions::priemery());
     $priemeryTable->addRows($priemery->getData());
     $priemeryContainer = new Container();
     $priemeryContainer->addChild(new Label('Nasledovné priemery sú prebraté z AISu, čiže to (ne)funguje presne rovnako:'));
     $priemeryContainer->addChild($priemeryTable);
     if ($priemeryCalculator->hasPriemer()) {
         $priemeryFajrText = '<p><br />Nasledovné vážené študijné priemery sú počítané Fajrom priebežne z tabuľky Hodnotenia, <strong>preto nemôžu byť považované ako oficiálne</strong>:<br /><br />';
         $priemeryFajrText .= $priemeryCalculator->getHtml();
         $priemeryFajrText .= '</p>';
         $priemeryContainer->addChild(new Label($priemeryFajrText));
     }
     $priemeryCollapsible = new Collapsible(new HtmlHeader('Priemery'), $priemeryContainer);
     return $hodnoteniaCollapsible->getHtml() . $priemeryCollapsible->getHtml();
 }
Example #8
Show file File: TextDescriptor.php Project: Chaireeee/chaireeee
0
 /**
  * {@inheritdoc}
  */
 protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = array())
 {
     $event = array_key_exists('event', $options) ? $options['event'] : null;
     $label = 'Registered listeners';
     if (null !== $event) {
         $label .= sprintf(' for event <info>%s</info>', $event);
     } else {
         $label .= ' by event';
     }
     $this->writeText($this->formatSection('event_dispatcher', $label) . "\n", $options);
     $registeredListeners = $eventDispatcher->getListeners($event);
     if (null !== $event) {
         $this->writeText("\n");
         $table = new Table($this->getOutput());
         $table->getStyle()->setCellHeaderFormat('%s');
         $table->setHeaders(array('Order', 'Callable'));
         foreach ($registeredListeners as $order => $listener) {
             $table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($listener)));
         }
         $this->renderTable($table, true);
     } else {
         ksort($registeredListeners);
         foreach ($registeredListeners as $eventListened => $eventListeners) {
             $this->writeText(sprintf("\n<info>[Event]</info> %s\n", $eventListened), $options);
             $table = new Table($this->getOutput());
             $table->getStyle()->setCellHeaderFormat('%s');
             $table->setHeaders(array('Order', 'Callable'));
             foreach ($eventListeners as $order => $eventListener) {
                 $table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($eventListener)));
             }
             $this->renderTable($table, true);
         }
     }
 }
Example #9
Show file File: BaseComparator.php Project: atiarda/bolt
0
 /**
  * Check that a single table's columns and indices are valid.
  *
  * @param Table $fromTable
  * @param Table $toTable
  */
 protected function checkTable(Table $fromTable, Table $toTable)
 {
     $tableName = $fromTable->getName();
     $diff = (new Comparator())->diffTable($fromTable, $toTable);
     if ($diff !== false) {
         $this->diffs[$tableName] = $diff;
     }
 }
Example #10
Show file File: TableDiffTest.php Project: kalaspuffar/php-orm-benchmark
0
 private function createTableDiff(Table $fromTable = null, Table $toTable = null)
 {
     if (null === $fromTable) {
         $fromTable = new Table('users');
     }
     if (null === $toTable) {
         $toTable = new Table('users');
     }
     return new TableDiff($fromTable, $toTable);
 }
Example #11
Show file File: SQLiteAdapterTest.php Project: askzap/ultimate
0
 public function testDropForeignKey()
 {
     $refTable = new \Phinx\Db\Table('ref_table', array(), $this->adapter);
     $refTable->addColumn('field1', 'string')->save();
     $table = new \Phinx\Db\Table('table', array(), $this->adapter);
     $table->addColumn('ref_table_id', 'integer')->save();
     $fk = new \Phinx\Db\Table\ForeignKey();
     $fk->setReferencedTable($refTable)->setColumns(array('ref_table_id'))->setReferencedColumns(array('id'));
     $this->adapter->addForeignKey($table, $fk);
     $this->adapter->dropForeignKey($table->getName(), array('ref_table_id'));
     $this->assertFalse($this->adapter->hasForeignKey($table->getName(), array('ref_table_id')));
 }
Example #12
Show file File: ProxyAdapterTest.php Project: askzap/ultimate
0
 public function testProxyAdapterCanInvertAddForeignKey()
 {
     $table = new \Phinx\Db\Table('atable');
     $refTable = new \Phinx\Db\Table('refTable');
     $fk = new \Phinx\Db\Table\ForeignKey();
     $fk->setReferencedTable($refTable)->setColumns(array('ref_table_id'))->setReferencedColumns(array('id'));
     $this->adapter->addForeignKey($table, $fk);
     $commands = $this->adapter->getInvertedCommands();
     $this->assertEquals('dropForeignKey', $commands[0]['name']);
     $this->assertEquals('atable', $commands[0]['arguments'][0]);
     $this->assertContains('ref_table_id', $commands[0]['arguments'][1]);
 }
Example #13
Show file File: MysqlAdapterTest.php Project: secteofilandia/ieducar
0
 public function testHasForeignKeyWithConstraint()
 {
     $refTable = new \Phinx\Db\Table('ref_table', array(), $this->adapter);
     $refTable->addColumn('field1', 'string')->save();
     $table = new \Phinx\Db\Table('table', array(), $this->adapter);
     $table->addColumn('ref_table_id', 'integer')->save();
     $fk = new \Phinx\Db\Table\ForeignKey();
     $fk->setReferencedTable($refTable)->setColumns(array('ref_table_id'))->setConstraint("my_constraint")->setReferencedColumns(array('id'));
     $this->adapter->addForeignKey($table, $fk);
     $this->assertTrue($this->adapter->hasForeignKey($table->getName(), array('ref_table_id'), 'my_constraint'));
     $this->assertFalse($this->adapter->hasForeignKey($table->getName(), array('ref_table_id'), 'my_constraint2'));
 }
Example #14
Show file File: PropelTableComparator.php Project: kalaspuffar/php-orm-benchmark
0
 /**
  * Compute and return the difference between two table objects
  *
  * @param Column  $fromTable
  * @param Column  $toTable
  * @param boolean $caseInsensitive Whether the comparison is case insensitive.
  *                                 False by default.
  *
  * @return PropelTableDiff|boolean return false if the two tables are similar
  */
 public static function computeDiff(Table $fromTable, Table $toTable, $caseInsensitive = false)
 {
     $tc = new self();
     $tc->setFromTable($fromTable);
     $tc->setToTable($toTable);
     $differences = 0;
     $differences += $tc->compareColumns($caseInsensitive);
     $differences += $tc->comparePrimaryKeys($caseInsensitive);
     $differences += $tc->compareIndices($caseInsensitive);
     $differences += $tc->compareForeignKeys($caseInsensitive);
     return $differences > 0 ? $tc->getTableDiff() : false;
 }
Example #15
Show file File: ComparatorTest.php Project: llinder/FrameworkBenchmarks
0
 public function testDetectChangeIdentifierType()
 {
     $this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.');
     $tableA = new Table("foo");
     $tableA->addColumn('id', 'integer', array('autoincrement' => false));
     $tableB = new Table("foo");
     $tableB->addColumn('id', 'integer', array('autoincrement' => true));
     $c = new Comparator();
     $tableDiff = $c->diffTable($tableA, $tableB);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\TableDiff', $tableDiff);
     $this->assertArrayHasKey('id', $tableDiff->changedColumns);
 }
Frequently Used Methods