コード例 #1
0
 /**
  * Create all of the tables relationships.
  */
 protected function createRelationships()
 {
     foreach ($this->table->getRelationships() as $relationship) {
         $this->content .= "            \$table->foreign('{$relationship->tableColumn}')->" . "references('{$relationship->relationshipColumn}')->on('{$relationship->relationshipTable}');\n";
     }
 }
コード例 #2
0
 /**
  * Create the function call based on the column on the line.
  *
  * @param Table $table
  * @param $line
  * @param $matches
  */
 protected function createMigrationFunctionCall(Table $table, $line, $matches)
 {
     $line = str_replace('"', "'", $line);
     $segments = explode("'", $line);
     $matches[0] = preg_replace('/>| |,/', '', $matches[0]);
     switch ($matches[0]) {
         case 'primary':
             $table->setPrimaryKey($segments[1]);
             break;
         case 'unique':
             $table->getColumn($segments[1])->unique = true;
             break;
         case 'renameColumn':
             $table->renameColumn($segments[1], $segments[3]);
             break;
         case 'foreign':
             $table->addRelationship(new Relationship($segments[1], $segments[3], $segments[5]));
             break;
         case 'dropColumn':
         case 'dropIfExists':
             $table->dropColumn($segments[1]);
             break;
         case 'dropForeign':
             $table->dropRelationship($segments[1]);
             break;
         case 'dropSoftDeletes':
             $table->dropColumn('softDeletes');
             break;
         case 'dropTimestamps':
             $table->dropColumn('timestamps');
             break;
         case 'timestamps':
         case 'softDeletes':
         case 'nullableTimestamps':
         case 'rememberToken':
             $segments[1] = $matches[0];
         case 'string':
         case 'integer':
         case 'increments':
         case 'bigIncrements':
         case 'bigInteger':
         case 'smallInteger':
         case 'float':
         case 'double':
         case 'decimal':
         case 'boolean':
         case 'date':
         case 'dateTime':
         case 'datetime':
         case 'time':
         case 'timestamp':
         case 'text':
         case 'binary':
         case 'morphs':
         case 'mediumText':
         case 'longText':
         case 'mediumInteger':
         case 'tinyInteger':
         case 'unsignedBigInteger':
         case 'unsignedInteger':
         case 'enum':
             $table->addColumn($this->createStandardColumn($matches, $segments, $line));
             break;
         case 'index':
         case 'dropUnique':
             echo "ERROR, cannot handle " . $matches[0] . PHP_EOL;
             var_dump($segments);
             break;
         default:
             echo "Unknown table operation: " . $matches[0] . PHP_EOL;
             exit;
     }
     $matches = null;
 }
コード例 #3
0
 public function testSetPrimaryKey()
 {
     $tbl = new Table("test_table", 'MyISAM');
     $tbl->setPrimaryKey("primary test");
     $this->assertEquals("primary test", $tbl->getPrimaryKey());
 }