public function writeView(WriterInterface $writer) { if (!$this->isExternal()) { $namespace = $this->getConfig()->get(Formatter::CFG_NAMESPACE); $writer->indent()->write('<table name="%s" phpName="%s" namespace="%s" skipSql="true" readOnly="true">', $this->getRawViewName(), $this->getModelName(), $namespace)->write('</table>')->outdent(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
public function writeVendor(WriterInterface $writer) { $writer->write('<vendor type="mysql">'); $writer->indent(); $writer->write('<parameter name="Engine" value="%s" />', $this->parameters->get('tableEngine')); $writer->write('<parameter name="Charset" value="%s" />', $this->parameters->get('defaultCharacterSetName')); $writer->outdent(); $writer->write('</vendor>'); return $this; }
public function writeRelations(WriterInterface $writer) { $parentTable = $this->getParent()->getParent(); foreach ($this->foreigns as $foreign) { //if($foreign->getParent()->getParent()->getRawTableName() == $parentTable->getRawTableName()){ $writer->write('<foreign-key name="%s" foreignTable="%s" phpName="%s" refPhpName="%s" onDelete="%s" onUpdate="%s">', $foreign->parameters->get('name'), $foreign->getOwningTable()->getRawTableName(), $foreign->getOwningTable()->getModelName(), $foreign->getReferencedTable()->getModelName(), strtolower($foreign->parameters->get('deleteRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('deleteRule')), strtolower($foreign->parameters->get('updateRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('updateRule'))); $writer->indent(); $writer->write('<reference local="%s" foreign="%s" />', $foreign->getLocal()->getColumnName(), $foreign->getForeign()->getColumnName()); $writer->outdent(); $writer->write('</foreign-key>'); //} } return $this; }
public function writeRelations(WriterInterface $writer) { foreach ($this->foreignKeys as $foreign) { $writer->write('<foreign-key name="%s" foreignTable="%s" phpName="%s" refPhpName="%s" onDelete="%s" onUpdate="%s">', $foreign->parameters->get('name'), $foreign->getReferencedTable()->getRawTableName(), $foreign->getReferencedTable()->getModelName(), $foreign->getOwningTable()->getModelName(), strtolower($foreign->parameters->get('deleteRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('deleteRule')), strtolower($foreign->parameters->get('updateRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('updateRule'))); $writer->indent(); $locals = $foreign->getLocals(); $foreigns = $foreign->getForeigns(); for ($i = 0; $i < count($locals); $i++) { $writer->write('<reference local="%s" foreign="%s" />', $locals[$i]->getColumnName(), $foreigns[$i]->getColumnName()); } $writer->outdent(); $writer->write('</foreign-key>'); } return $this; }
public function writeReferences(WriterInterface $writer) { $writer->write('/**')->write(' * @var array')->write(' */')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if (count($_this->getForeignKeys())) { $writer->write('protected $_referenceMap = array('); $writer->indent(); foreach ($_this->getForeignKeys() as $foreignKey) { $foreignKey->write($writer); } $writer->outdent(); $writer->write(');'); } else { $writer->write('protected $_referenceMap = array();'); } }); return $this; }
public function writeReferences(WriterInterface $writer) { $writer->writeCallback(function (WriterInterface $writer, Table $_this = null) { if (count($_this->getColumns())) { // Get current column from this table foreach ($_this->getColumns() as $column) { // Get tables from the same schema foreach ($this->getParent() as $table) { // If not a pivot table if (!$table->isManyToMany()) { // Get foreignKeys from table foreach ($table->getForeignKeys() as $foreignKey) { // If current column is referenced by foreignKey if ($_this->getRawTableName() == $foreignKey->getReferencedTable()->getRawTableName() && $column->getColumnName() == $foreignKey->getForeign()->getColumnName()) { // Comment $writer->write('/**'); $writer->write(' * Relationship with ' . $foreignKey->getOwningTable()->getModelName() . '.'); $writer->write(' */'); // Start Method $writer->write('public function ' . Inflector::pluralize($foreignKey->getOwningTable()->getRawTableName()) . '()'); $writer->write('{'); $writer->indent(); // One to Many if ($foreignKey->isManyToOne()) { $writer->write('return $this->hasMany(\'' . $_this->getNamespace() . '\\' . $foreignKey->getOwningTable()->getModelName() . '\');'); } else { $writer->write('return $this->hasOne(\'' . $_this->getNamespace() . '\\' . $foreignKey->getOwningTable()->getModelName() . '\');'); } // End Method $writer->outdent(); $writer->write('}'); $writer->write(''); } } } else { if (count($table->getForeignKeys()) == 2) { // ForeignKey 1 $foreignKey1 = $table->getForeignKeys()[0]; // ForeignKey 2 $foreignKey2 = $table->getForeignKeys()[1]; // If current column is referenced by foreignKey if (($_this->getRawTableName() == $foreignKey1->getReferencedTable()->getRawTableName() || $_this->getRawTableName() == $foreignKey2->getReferencedTable()->getRawTableName()) && ($column->getColumnName() == $foreignKey1->getForeign()->getColumnName() || $column->getColumnName() == $foreignKey2->getForeign()->getColumnName())) { // Comment $writer->write('/**'); if ($_this->getRawTableName() != $foreignKey1->getReferencedTable()->getRawTableName()) { $writer->write(' * Relationship with ' . $foreignKey1->getReferencedTable()->getModelName() . '.'); } else { $writer->write(' * Relationship with ' . $foreignKey2->getReferencedTable()->getModelName() . '.'); } $writer->write(' */'); // Method if ($_this->getRawTableName() != $foreignKey1->getReferencedTable()->getRawTableName()) { $writer->write('public function ' . Inflector::pluralize($foreignKey1->getReferencedTable()->getRawTableName()) . '()'); } else { $writer->write('public function ' . Inflector::pluralize($foreignKey2->getReferencedTable()->getRawTableName()) . '()'); } $writer->write('{'); $writer->indent(); // Find out what foreignKey is this reference table and what the other table if ($_this->getRawTableName() != $foreignKey1->getReferencedTable()->getRawTableName()) { $writer->write('return $this->belongsToMany(\'' . $_this->getNamespace() . '\\' . $foreignKey1->getReferencedTable()->getModelName() . '\', \'' . $foreignKey1->getOwningTable()->getRawTableName() . '\', \'' . $foreignKey2->getForeign()->getColumnName() . '\', \'' . $foreignKey1->getForeign()->getColumnName() . '\');'); } else { $writer->write('return $this->belongsToMany(\'' . $_this->getNamespace() . '\\' . $foreignKey2->getReferencedTable()->getModelName() . '\', \'' . $foreignKey2->getOwningTable()->getRawTableName() . '\', \'' . $foreignKey1->getForeign()->getColumnName() . '\', \'' . $foreignKey2->getForeign()->getColumnName() . '\');'); } $writer->outdent(); $writer->write('}'); $writer->write(''); } } } } } } }); return $this; }
public function writeToString(WriterInterface $writer) { $throwException = false; if ($this->getColumns()->columnExits('name')) { $column = $this->getColumns()->getColumnByName('name'); } else { foreach ($this->getColumns() as $c) { /** @var Column $c */ if ($c->isPrimary()) { $column = $c; break; } } } /** @var \Column $column */ if ($column && $column->parseComment('skip') == 'true') { return; } if (!isset($column)) { $throwException = true; $column = null; } //* @throws MethodNotImplementedException $writer->write('/**')->write(' * To string entity.')->write(' *')->write(' * @return string'); if ($throwException) { $writer->write(' *')->write(' * @throws \\Symfony\\Component\\Intl\\Exception\\MethodNotImplementedException'); } $writer->write(' */')->write('public function __toString()')->write('{'); if (!isset($column) && $throwException) { $writer->indent()->write('throw new \\Symfony\\Component\\Intl\\Exception\\MethodNotImplementedException(__METHOD__);')->write('')->write("return '';")->outdent(); } else { $name = $column->getPhpColumnName(); $writer->indent()->write("return (string) \$this->{$name};")->outdent(); } $writer->write('}'); return $this; }
public function writeToString(WriterInterface $writer) { $throwException = false; if ($this->getColumns()->columnExits('name')) { $column = $this->getColumns()->getColumnByName('name'); } else { if ($this->getColumns()->columnExits('id')) { $column = $this->getColumns()->getColumnByName('id'); } else { $throwException = true; $column = null; } } //* @throws MethodNotImplementedException $writer->write('/**')->write(' * to string entity')->write(' * @return string'); if ($throwException) { $writer->write(' * @throws \\Symfony\\Component\\Intl\\Exception\\MethodNotImplementedException'); } $writer->write(' */')->write('public function __toString()')->write('{'); if (!isset($column) && $throwException) { $writer->indent()->write('throw new \\Symfony\\Component\\Intl\\Exception\\MethodNotImplementedException(__METHOD__);')->write("return '';")->outdent(); } else { $name = $column->getPhpColumnName(); $writer->indent()->write("return (string)\$this->{$name};")->outdent(); } $writer->write('}'); return $this; }