예제 #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
 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());
 }
예제 #3
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)));
 }
예제 #4
0
 private function createColumnDefault(Column $column)
 {
     if ($column->allowNull() && $column->getDefault() === null) {
         return ' DEFAULT NULL';
     }
     if ($column->getDefault() !== null) {
         $default = ' DEFAULT ';
         if ($column->getType() == Column::TYPE_INTEGER) {
             return $default .= $column->getDefault();
         }
         if ($column->getType() == Column::TYPE_BOOLEAN) {
             return $default .= intval($column->getDefault());
         }
         return $default .= "'" . $column->getDefault() . "'";
     }
     return '';
 }