public function getInputFields() { $fields = []; $this->commandObj->info('Specify fields for the model (skip id & timestamp fields, will be added automatically)'); $this->commandObj->info('Enter exit to finish'); while (true) { $fieldInputStr = $this->commandObj->ask('Field: (field_name:field_database_type)', ''); if (empty($fieldInputStr) || $fieldInputStr == false || $fieldInputStr == 'exit') { break; } if (!GeneratorUtils::validateFieldInput($fieldInputStr)) { $this->commandObj->error('Invalid Input. Try again'); continue; } $type = $this->commandObj->ask('Enter field html input type (text): ', 'text'); $validations = $this->commandObj->ask('Enter validations: ', false); $validations = $validations == false ? '' : $validations; $fields[] = GeneratorUtils::processFieldInput($fieldInputStr, $type, $validations); } return $fields; }
public function generateFieldsFromTable() { $this->schema->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $columns = $this->schema->listTableColumns($this->tableName); $fields = []; foreach ($columns as $column) { switch ($column->getType()->getName()) { case 'integer': $fieldInput = $this->generateIntFieldInput($column->getName(), 'integer', $column); $type = 'number'; break; case 'smallint': $fieldInput = $this->generateIntFieldInput($column->getName(), 'smallInteger', $column); $type = 'number'; break; case 'bigint': $fieldInput = $this->generateIntFieldInput($column->getName(), 'bigInteger', $column); $type = 'number'; break; case 'boolean': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'boolean'); $type = 'text'; break; case 'datetime': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'dateTime'); $type = 'date'; break; case 'datetimetz': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'dateTimeTz'); $type = 'date'; break; case 'date': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'date'); $type = 'date'; break; case 'time': $fieldInput = $this->generateSingleFieldInput($column->getName(), 'time'); $type = 'text'; break; case 'decimal': $fieldInput = $this->generateDecimalInput($column, 'decimal'); $type = 'number'; break; case 'float': $fieldInput = $this->generateFloatInput($column); $type = 'number'; break; case 'string': $fieldInput = $this->generateStringInput($column); $type = 'text'; break; case 'text': $fieldInput = $this->generateTextInput($column); $type = 'textarea'; break; default: $fieldInput = $this->generateTextInput($column); $type = 'text'; } if (strtolower($column->getName()) == 'password') { $type = 'password'; } elseif (strtolower($column->getName()) == 'email') { $type = 'email'; } if (!empty($fieldInput)) { // $fieldInput .= $this->checkForDefault($column); // $fieldInput .= $this->checkForNullable($column); // $fieldInput .= $this->checkForUnique($column); $fields[] = GeneratorUtils::processFieldInput($fieldInput, $type, ''); } } return $fields; }