예제 #1
0
 protected function remapType(Column $column)
 {
     if (!isset($this->typeMap[$column->getType()])) {
         throw new Exception('Type "' . $column->getType() . '" is not allowed');
     }
     return $this->typeMap[$column->getType()];
 }
예제 #2
0
 protected function createEnumSetColumn(Column $column, Table $table)
 {
     $values = [];
     if ($column->getType() == Column::TYPE_ENUM) {
         $values = $column->getValues();
     } elseif ($column->getType() === Column::TYPE_SET) {
         $this->createSetCombinations($column->getValues(), '', $values);
     }
     return sprintf($this->remapType($column), $column->getName(), implode(',', array_map(function ($value) {
         return "'{$value}'";
     }, $values)));
 }
예제 #3
0
 private function createColumnCharset(Column $column)
 {
     return $this->createCharset($column->getCharset(), $column->getCollation(), ' ');
 }
예제 #4
0
 public function testComplex()
 {
     $column = new Column('title', 'string', ['null' => true, 'default' => '', 'length' => 255, 'after' => 'id']);
     $this->assertEquals('title', $column->getName());
     $this->assertEquals('string', $column->getType());
     $this->assertTrue($column->allowNull());
     $this->assertEquals('', $column->getDefault());
     $this->assertEquals(255, $column->getLength());
     $this->assertEquals(255, $column->getLength(100));
     $this->assertNull($column->getDecimals());
     $this->assertEquals(2, $column->getDecimals(2));
     $this->assertTrue($column->isSigned());
     $this->assertFalse($column->isAutoincrement());
     $this->assertFalse($column->isFirst());
     $this->assertEquals('id', $column->getAfter());
 }
예제 #5
0
 protected function createColumn(Column $column, Table $table)
 {
     $col = $this->escapeString($column->getName()) . ' ' . $this->createType($column, $table);
     if ($column->getDefault() !== null || $column->isAutoincrement()) {
         $col .= ' DEFAULT ';
         if ($column->isAutoincrement()) {
             $col .= "nextval('" . $table->getName() . "_seq'::regclass)";
         } elseif ($column->getType() == Column::TYPE_INTEGER) {
             $col .= $column->getDefault();
         } elseif ($column->getType() == Column::TYPE_BOOLEAN) {
             $col .= $column->getDefault() ? 'true' : 'false';
         } else {
             $col .= "'" . $column->getDefault() . "'";
         }
     } elseif ($column->allowNull() && $column->getDefault() === null) {
         $col .= ' DEFAULT NULL';
     }
     $col .= $column->allowNull() ? '' : ' NOT NULL';
     return $col;
 }
예제 #6
0
파일: Table.php 프로젝트: lulco/phoenix
 /**
  * @param Column $column
  * @return Table
  */
 public function addColumn(Column $column)
 {
     $this->columns[$column->getName()] = $column;
     return $this;
 }