Ejemplo n.º 1
0
 /**
  * Parse the field definition line and build the necessary data structures
  * @param  string $line  The field line to be parsed
  * @param  string $model The name of the model to which the field belongs
  * @param  string $type  The type of the definition: model/table
  * @return void
  */
 public function parseFieldDefinitionLine($line, $model, $type)
 {
     // Is this a model definition, or a table definition?
     // We won't add anything to the model list in case of a table definition
     $isModelDefinition = $type == 'model';
     // Parse the field definition
     $parsed = $this->fieldParser->parse(trim($line));
     // Check for errors
     if (!$parsed) {
         throw new ParseError("Could not parse field line. Check for errors like misplaced quotes.");
     }
     // Check if the field is timestamps
     if ($parsed['type'] == 'timestamps') {
         $isModelDefinition && $this->modelList->setTimestamps($model);
         $this->migrationList->setTimestamps($model);
         return;
     }
     // Check if the field is softDeletes
     if ($parsed['type'] == 'softDeletes') {
         $isModelDefinition && $this->modelList->setSoftDeletes($model);
         $this->migrationList->setSoftDeletes($model);
         return;
     }
     // Check if field type is increments
     if ($parsed['type'] == 'increments') {
         $isModelDefinition && $this->modelList->setPrimaryKey($model, $parsed['name']);
         $this->migrationList->setPrimaryKey($model, $parsed['name']);
         return;
     }
     // For other fields, add them to the current migration
     $this->migrationList->addColumn($model, $parsed);
 }
 private function getParsedResults($input)
 {
     $f = new FieldParser();
     return $f->parse($input);
 }