php Propel-Generator-Model-Table类(方法)实例源码

下面列出了php Propel-Generator-Model-Table 类(方法)源码代码实例,从而了解它的用法。

作者:dracon    项目:forked-php-orm-benchmar   
public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey()) {
         $pattern = 'CONSTRAINT %s PRIMARY KEY (%s)';
         return sprintf($pattern, $this->quoteIdentifier($this->getPrimaryKeyName($table)), $this->getColumnListDDL($table->getPrimaryKey()));
     }
 }

作者:robin85    项目:Propel   
public function testTable()
 {
     $b = new Behavior();
     $this->assertNull($b->getTable(), 'Behavior Table is null by default');
     $t = new Table();
     $t->setCommonName('fooTable');
     $b->setTable($t);
     $this->assertEquals($b->getTable(), $t, 'setTable() sets the name, and getTable() gets it');
 }

作者:Swissalp    项目:Propel   
/**
  * Adds a unique constraint to the table to enforce uniqueness of the slug_column
  *
  * @param Table $table
  */
 protected function addUniqueConstraint(Table $table)
 {
     $unique = new Unique($this->getColumnForParameter('slug_column'));
     $unique->setName($table->getCommonName() . '_slug');
     $unique->addColumn($table->getColumn($this->getParameter('slug_column')));
     if ($this->getParameter('scope_column')) {
         $unique->addColumn($table->getColumn($this->getParameter('scope_column')));
     }
     $table->addUnique($unique);
 }

作者:rouff    项目:Propel   
public function testTableNamespaceAndDbNamespace()
 {
     $d = new Database('fooDb');
     $d->setNamespace('Baz');
     $t = new Table('fooTable');
     $t->setNamespace('Foo\\Bar');
     $d->addTable($t);
     $builder = new TestableOMBuilder2($t);
     $this->assertEquals('Baz\\Foo\\Bar', $builder->getNamespace(), 'Builder namespace is composed from the database and table namespaces when both are set');
 }

作者:spryke    项目:Prope   
/**
  * @return void
  */
 protected function _before()
 {
     $config = new QuickGeneratorConfig();
     $table = new Table('Foo');
     $column = new Column('testColumn', PropelTypes::INTEGER);
     $table->addColumn($column);
     $table->setNamespace('Unit\\Spryker\\Zed\\Propel\\Business\\Builder\\QueryBuilder');
     $table->setDatabase(new Database('TestDB', new DefaultPlatform()));
     foreach ($this->getFilesToGenerate() as $fileName => $builderClass) {
         $builder = new $builderClass($table);
         $builder->setGeneratorConfig($config);
         $this->writePropelFile($builder, $fileName);
     }
 }

作者:bondarovic    项目:Propel   
/**
  * Returns whether or not this column has a platform adapter.
  *
  * @return boolean
  */
 public function hasPlatform()
 {
     if (null === $this->parentTable) {
         return false;
     }
     return $this->parentTable->getPlatform() ? true : false;
 }

作者:nald    项目:cyberde   
/**
  * Build the fields in the FormType.
  *
  * @param Table $table Table from which the fields will be extracted.
  *
  * @return string The FormType code.
  */
 protected function buildFormFields(Table $table)
 {
     $buildCode = '';
     foreach ($table->getColumns() as $column) {
         if ($column->isPrimaryKey()) {
             continue;
         }
         $name = $column->getPhpName();
         // Use foreignKey table name, so the TypeGuesser gets it right
         if ($column->isForeignKey()) {
             /** @var ForeignKey $foreignKey */
             $foreignKey = current($column->getForeignKeys());
             $name = $foreignKey->getForeignTable()->getPhpName();
         }
         $buildCode .= sprintf("\n        \$builder->add('%s');", lcfirst($name));
     }
     return $buildCode;
 }

作者:dracon    项目:forked-php-orm-benchmar   
/**
  * Returns the list of other foreign keys starting on the same table.
  * Used in many-to-many relationships.
  *
  * @return ForeignKey[]
  */
 public function getOtherFks()
 {
     $fks = [];
     foreach ($this->parentTable->getForeignKeys() as $fk) {
         if ($fk !== $this) {
             $fks[] = $fk;
         }
     }
     return $fks;
 }

作者:diside    项目:Propel   
/**
  * Convenience method to returns the Platform class for this table (database).
  * @return PlatformInterface
  */
 public function getPlatform()
 {
     if (null === $this->platform) {
         // try to load the platform from the table
         $table = $this->getTable();
         if ($table && ($database = $table->getDatabase())) {
             $this->setPlatform($database->getPlatform());
         }
     }
     if (!$this->table->isIdentifierQuotingEnabled()) {
         $this->platform->setIdentifierQuoting(false);
     }
     return $this->platform;
 }

作者:malukenh    项目:Propel   
public function endElement($parser, $name)
 {
     if ('index' === $name) {
         $this->currTable->addIndex($this->currIndex);
     } else {
         if ('unique' === $name) {
             $this->currTable->addUnique($this->currUnique);
         }
     }
     if (self::DEBUG) {
         print 'endElement(' . $name . ") called\n";
     }
     $this->popCurrentSchemaTag();
 }

作者:diside    项目:Propel   
protected function validateTableColumns(Table $table)
 {
     if (!$table->hasPrimaryKey() && !$table->isSkipSql()) {
         $this->errors[] = sprintf('Table "%s" does not have a primary key defined. Propel requires all tables to have a primary key.', $table->getName());
     }
     $phpNames = [];
     foreach ($table->getColumns() as $column) {
         if (in_array($column->getPhpName(), $phpNames)) {
             $this->errors[] = sprintf('Column "%s" declares a phpName already used in table "%s"', $column->getName(), $table->getName());
         }
         $phpNames[] = $column->getPhpName();
     }
 }

作者:RafalFilipe    项目:Propel   
public function getAddTableDDL(Table $table)
 {
     $tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
     $lines = array();
     foreach ($table->getColumns() as $column) {
         $lines[] = $this->getColumnDDL($column);
     }
     if ($table->hasPrimaryKey() && count($table->getPrimaryKey()) > 1) {
         $lines[] = $this->getPrimaryKeyDDL($table);
     }
     foreach ($table->getUnices() as $unique) {
         $lines[] = $this->getUniqueDDL($unique);
     }
     $sep = ",\n    ";
     $pattern = "\n%sCREATE TABLE %s\n(\n    %s\n);\n";
     return sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines));
 }

作者:Swissalp    项目:Propel   
/**
  * Adds the switch-statement for looking up the array-key name for toArray
  * @see toArray
  */
 protected function addToArrayKeyLookUp($phpName, Table $table, $plural)
 {
     if ($phpName == "") {
         $phpName = $table->getPhpName();
     }
     $camelCaseName = $table->getCamelCaseName();
     $fieldName = $table->getName();
     if ($plural) {
         $phpName = $this->getPluralizer()->getPluralForm($phpName);
         $camelCaseName = $this->getPluralizer()->getPluralForm($camelCaseName);
         $fieldName = $this->getPluralizer()->getPluralForm($fieldName);
     }
     return "\n                switch (\$keyType) {\n                    case TableMap::TYPE_CAMELNAME:\n                        \$key = '" . $camelCaseName . "';\n                        break;\n                    case TableMap::TYPE_FIELDNAME:\n                        \$key = '" . $fieldName . "';\n                        break;\n                    default:\n                        \$key = '" . $phpName . "';\n                }\n        ";
 }

作者:diside    项目:Propel   
public function testGetPrimaryKeyDDLCompositeKey()
 {
     $table = new Table('foo');
     $column1 = new Column('bar1');
     $column1->setPrimaryKey(true);
     $table->addColumn($column1);
     $column2 = new Column('bar2');
     $column2->setPrimaryKey(true);
     $table->addColumn($column2);
     $expected = 'PRIMARY KEY ([bar1],[bar2])';
     $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
 }

作者:kalaspuffa    项目:php-orm-benchmar   
/**
  * Builds the DDL SQL to drop the primary key of a table.
  *
  * @param  Table  $table
  * @return string
  */
 public function getDropPrimaryKeyDDL(Table $table)
 {
     if (!$table->hasPrimaryKey()) {
         return '';
     }
     $pattern = "\nALTER TABLE %s DROP PRIMARY KEY;\n";
     return sprintf($pattern, $this->quoteIdentifier($table->getName()));
 }

作者:a-melnichu    项目:Movies-Dem   
/**
  * Computes the table namespace based on the current relative or
  * absolute table namespace and the database namespace.
  *
  * @param  Table  $table
  * @return string
  */
 private function computeTableNamespace(Table $table)
 {
     $namespace = $table->getNamespace();
     if ($this->isAbsoluteNamespace($namespace)) {
         $namespace = ltrim($namespace, '\\');
         $table->setNamespace($namespace);
         return $namespace;
     }
     if ($namespace = $this->getNamespace()) {
         if ($table->getNamespace()) {
             $namespace .= '\\' . $table->getNamespace();
         }
         $table->setNamespace($namespace);
     }
     return $namespace;
 }

作者:diside    项目:Propel   
public function testCompareSeveralRenamedSameColumns()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c2->getDomain()->replaceSize(255);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col4');
     $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c4->getDomain()->replaceSize(255);
     $t2->addColumn($c4);
     $c5 = new Column('col5');
     $c5->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c5->getDomain()->replaceSize(255);
     $t2->addColumn($c5);
     $c6 = new Column('col3');
     $c6->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c6->getDomain()->replaceSize(255);
     $t2->addColumn($c6);
     // col1 and col2 were renamed
     $tc = new TableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(2, $nbDiffs);
     $this->assertEquals([[$c1, $c4], [$c2, $c5]], $tableDiff->getRenamedColumns());
     $this->assertEquals([], $tableDiff->getAddedColumns());
     $this->assertEquals([], $tableDiff->getRemovedColumns());
     $this->assertEquals([], $tableDiff->getModifiedColumns());
 }

作者:kalaspuffa    项目:php-orm-benchmar   
/**
  * Returns the string representation of this object.
  *
  * @return string
  */
 public function __toString()
 {
     $ret = '';
     $ret .= sprintf("  %s:\n", $this->fromTable->getName());
     if ($addedColumns = $this->getAddedColumns()) {
         $ret .= "    addedColumns:\n";
         foreach ($addedColumns as $colname => $column) {
             $ret .= sprintf("      - %s\n", $colname);
         }
     }
     if ($removedColumns = $this->getRemovedColumns()) {
         $ret .= "    removedColumns:\n";
         foreach ($removedColumns as $colname => $column) {
             $ret .= sprintf("      - %s\n", $colname);
         }
     }
     if ($modifiedColumns = $this->getModifiedColumns()) {
         $ret .= "    modifiedColumns:\n";
         foreach ($modifiedColumns as $colDiff) {
             $ret .= $colDiff->__toString();
         }
     }
     if ($renamedColumns = $this->getRenamedColumns()) {
         $ret .= "    renamedColumns:\n";
         foreach ($renamedColumns as $columnRenaming) {
             list($fromColumn, $toColumn) = $columnRenaming;
             $ret .= sprintf("      %s: %s\n", $fromColumn->getName(), $toColumn->getName());
         }
     }
     if ($addedIndices = $this->getAddedIndices()) {
         $ret .= "    addedIndices:\n";
         foreach ($addedIndices as $indexName => $index) {
             $ret .= sprintf("      - %s\n", $indexName);
         }
     }
     if ($removedIndices = $this->getRemovedIndices()) {
         $ret .= "    removedIndices:\n";
         foreach ($removedIndices as $indexName => $index) {
             $ret .= sprintf("      - %s\n", $indexName);
         }
     }
     if ($modifiedIndices = $this->getModifiedIndices()) {
         $ret .= "    modifiedIndices:\n";
         foreach ($modifiedIndices as $indexName => $indexDiff) {
             $ret .= sprintf("      - %s\n", $indexName);
         }
     }
     if ($addedFks = $this->getAddedFks()) {
         $ret .= "    addedFks:\n";
         foreach ($addedFks as $fkName => $fk) {
             $ret .= sprintf("      - %s\n", $fkName);
         }
     }
     if ($removedFks = $this->getRemovedFks()) {
         $ret .= "    removedFks:\n";
         foreach ($removedFks as $fkName => $fk) {
             $ret .= sprintf("      - %s\n", $fkName);
         }
     }
     if ($modifiedFks = $this->getModifiedFks()) {
         $ret .= "    modifiedFks:\n";
         foreach ($modifiedFks as $fkName => $fkFromTo) {
             $ret .= sprintf("      %s:\n", $fkName);
             list($fromFk, $toFk) = $fkFromTo;
             $fromLocalColumns = json_encode($fromFk->getLocalColumns());
             $toLocalColumns = json_encode($toFk->getLocalColumns());
             if ($fromLocalColumns != $toLocalColumns) {
                 $ret .= sprintf("          localColumns: from %s to %s\n", $fromLocalColumns, $toLocalColumns);
             }
             $fromForeignColumns = json_encode($fromFk->getForeignColumns());
             $toForeignColumns = json_encode($toFk->getForeignColumns());
             if ($fromForeignColumns != $toForeignColumns) {
                 $ret .= sprintf("          foreignColumns: from %s to %s\n", $fromForeignColumns, $toForeignColumns);
             }
             if ($fromFk->normalizeFKey($fromFk->getOnUpdate()) != $toFk->normalizeFKey($toFk->getOnUpdate())) {
                 $ret .= sprintf("          onUpdate: from %s to %s\n", $fromFk->getOnUpdate(), $toFk->getOnUpdate());
             }
             if ($fromFk->normalizeFKey($fromFk->getOnDelete()) != $toFk->normalizeFKey($toFk->getOnDelete())) {
                 $ret .= sprintf("          onDelete: from %s to %s\n", $fromFk->getOnDelete(), $toFk->getOnDelete());
             }
         }
     }
     return $ret;
 }

作者:RafalFilipe    项目:Propel   
public function testCompareSeveralColumnDifferences()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c2->setNotNull(true);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col1');
     $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c4->getDomain()->replaceScale(2);
     $c4->getDomain()->replaceSize(3);
     $c4->setNotNull(true);
     $c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c4);
     $c5 = new Column('col22');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c5->setNotNull(true);
     $t2->addColumn($c5);
     $c6 = new Column('col4');
     $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR'));
     $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c6);
     // col1 was modified, col2 was renamed, col3 was removed, col4 was added
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns());
     $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns());
     $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns());
     $columnDiff = PropelColumnComparator::computeDiff($c1, $c4);
     $this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns());
 }

作者:kalaspuffa    项目:php-orm-benchmar   
/**
  * Returns the SQL for the primary key of a Table object
  * @return string
  */
 public function getPrimaryKeyDDL(Table $table)
 {
     if ($table->hasPrimaryKey() && !$table->hasAutoIncrementPrimaryKey()) {
         return 'PRIMARY KEY (' . $this->getColumnListDDL($table->getPrimaryKey()) . ')';
     }
     return '';
 }


问题


面经


文章

微信
公众号

扫码关注公众号