/** * generate * * Generate structure file. * * @see BaseGenerator */ public function generate(ParameterHolder $input, array $output = []) { $table_oid = $this->checkRelationInformation(); $field_information = $this->getFieldInformation($table_oid); $primary_key = $this->getPrimaryKey($table_oid); $table_comment = $this->getTableComment($table_oid); if ($table_comment === null) { $table_comment = <<<TEXT Class and fields comments are inspected from table and fields comments. Just add comments in your database and they will appear here. @see http://www.postgresql.org/docs/9.0/static/sql-comment.html TEXT; } $this->outputFileCreation($output)->saveFile($this->filename, $this->mergeTemplate(['namespace' => $this->namespace, 'class_name' => $input->getParameter('class_name', Inflector::studlyCaps($this->relation)), 'relation' => sprintf("%s.%s", $this->schema, $this->relation), 'primary_key' => join(', ', array_map(function ($val) { return sprintf("'%s'", $val); }, $primary_key)), 'add_fields' => $this->formatAddFields($field_information), 'table_comment' => $this->createPhpDocBlockFromText($table_comment), 'fields_comment' => $this->formatFieldsComment($field_information)])); return $output; }
/** * checkOverwrite * * Check if the file exists and if it the write is forced. * * @access protected * @param ParameterHolder $input * @throws GeneratorException * @return BaseGenerator $this */ protected function checkOverwrite(ParameterHolder $input) { if (file_exists($this->filename) && $input->getParameter('force') !== true) { throw new GeneratorException(sprintf("Cannot overwrite file '%s' without --force option.", $this->filename)); } return $this; }