public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { $writer->open($this->getTableFileName())->write('%s:', $this->getModelName())->indent()->writeIf($actAs = trim($this->getActAsBehaviour()), $actAs)->write('tableName: ' . ($this->getDocument()->getConfig()->get(Formatter::CFG_EXTEND_TABLENAME_WITH_SCHEMA) ? $this->getSchema()->getName() . '.' : '') . $this->getRawTableName())->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->getColumns()->write($writer); })->writeCallback(function (WriterInterface $writer, Table $_this = null) { $externalRelation = $_this->getExternalRelations(); if (count($_this->getRelations()) || $externalRelation) { $writer->write('relations:'); $writer->indent(); foreach ($_this->getRelations() as $relation) { $relation->write($writer); } if ($externalRelation) { $writer->write($externalRelation); } $writer->outdent(); } })->writeCallback(function (WriterInterface $writer, Table $_this = null) { if (count($_this->getIndexes())) { $writer->write('indexes:'); $writer->indent(); foreach ($_this->getIndexes() as $index) { $index->write($writer); } $writer->outdent(); } })->write('options:')->indent()->write('charset: ' . (($charset = $this->parameters->get('defaultCharacterSetName')) ? $charset : 'utf8'))->writeIf($engine = $this->parameters->get('tableEngine'), 'type: ' . $engine)->outdent()->outdent()->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
/** * (non-PHPdoc) * @see \MwbExporter\Model\Schema::write() */ public function write(WriterInterface $writer) { $writer->open($this->getDocument()->translateFilename($this))->write('<?xml version="1.0" encoding="UTF-8"?>')->write('<database name="%s" defaultIdMethod="native">', $this->getName())->writeCallback(function (WriterInterface $writer, Schema $_this = null) { $_this->writeSchema($writer); })->write('</database>')->close(); return $this; }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { $writer->open($this->getTableFileName())->write('<?php')->write('')->write('class ' . $this->getTablePrefix() . $this->getModelName() . 'Controller extends ' . $this->getParentTable())->write('{')->indent()->write('')->outdent()->write('}')->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { $writer->open($this->getTableFileName())->write('%s.%s = Ext.extend(%s, %s);', $this->getClassPrefix(), $this->getModelName(), $this->getParentClass(), $this->asModel())->write('')->write('%1$s.%2$s = Ext.extend(%1$s.%2$s, %3$s);', $this->getClassPrefix(), $this->getModelName(), $this->asUI())->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
/** * (non-PHPdoc) * @see \MwbExporter\Model\Schema::write() */ public function write(WriterInterface $writer) { $writer->open($this->getDocument()->translateFilename(null, $this))->write('<?xml version="1.0" encoding="UTF-8"?>')->writeCallback(function (WriterInterface $writer, Schema $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_XML)); } })->write('<database name="%s" defaultIdMethod="native">', $this->getName())->writeCallback(function (WriterInterface $writer, Schema $_this = null) { $_this->writeSchema($writer); })->write('</database>')->close(); return $this; }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { $writer->open($this->getTableFileName())->write('<?php')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_PHP))->write(''); } })->write('class ' . $this->getTablePrefix() . $this->getModelName() . 'Controller extends ' . $this->getParentTable())->write('{')->indent()->write('')->outdent()->write('}')->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
public function writeTable(WriterInterface $writer) { switch (true) { case $this->isExternal(): return self::WRITE_EXTERNAL; case $this->isManyToMany(): return self::WRITE_M2M; default: $writer->open($this->getTableFileName())->write($this->asYAML())->close(); return self::WRITE_OK; } }
/** * (non-PHPdoc) * @see \MwbExporter\Model\Schema::write() */ public function write(WriterInterface $writer) { $data = $this->asYAML(); $indent = $this->getConfig()->get(Formatter::CFG_INDENTATION); $yaml = new YAML($data, array('indent' => $indent, 'inline' => true, 'inline_size' => $this->getInlineSize($data) + ($this->getArrayLevel($data) - 1) * $indent)); $writer->open($this->getDocument()->translateFilename(null, $this))->writeCallback(function (WriterInterface $writer, Schema $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_YAML))->write(''); } })->write($yaml)->close(); return $this; }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { $writer->open($this->getTableFileName())->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_JS))->write(''); } })->write('%s.%s = Ext.extend(%s, %s);', $this->getClassPrefix(), $this->getModelName(), $this->getParentClass(), $this->asModel())->write('')->write('%1$s.%2$s = Ext.extend(%1$s.%2$s, %3$s);', $this->getClassPrefix(), $this->getModelName(), $this->asUI())->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
public function writeTable(WriterInterface $writer) { switch (true) { case $this->isExternal(): return self::WRITE_EXTERNAL; case $this->getConfig()->get(Formatter::CFG_SKIP_M2M_TABLES) && $this->isManyToMany(): return self::WRITE_M2M; default: $writer->open($this->getTableFileName()); $this->writeBody($writer); $writer->close(); return self::WRITE_OK; } }
public function writeTable(WriterInterface $writer) { switch (true) { case $this->isExternal(): return self::WRITE_EXTERNAL; case $this->getConfig()->get(Formatter::CFG_SKIP_M2M_TABLES) && $this->isManyToMany(): return self::WRITE_M2M; default: $this->getDocument()->addLog(sprintf('Writing table "%s"', $this->getModelName())); $writer->open($this->getTableFileName())->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_YAML))->write(''); } })->write($this->asYAML())->close(); return self::WRITE_OK; } }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { // $this->getModelName() return singular form with correct camel case // $this->getRawTableName() return original form with no camel case $writer->open($this->getTableFileName())->write('<?php')->write('')->write('use Illuminate\\Database\\Schema\\Blueprint;')->write('use Illuminate\\Database\\Migrations\\Migration;')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_PHP))->write(''); } })->write('class ' . $this->getTablePrefix() . $this->beautify($this->getRawTableName()) . $this->getTableSuffix() . ' extends ' . $this->getParentTable())->write('{')->indent()->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeUp($writer); })->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeDown($writer); })->outdent()->write('}')->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { /* FIXME: [Zend] Table name is one time in singular form, one time in plural form. * All table occurence need to be at the original form. * * $this->getModelName() return singular form with correct camel case * $this->getRawTableName() return original form with no camel case */ $writer->open($this->getTableFileName())->write('<?php')->write('')->write('class ' . $this->getTablePrefix() . $this->getSchema()->getName() . '_' . $this->getModelName() . ' extends ' . $this->getParentTable())->write('{')->indent()->write('/**')->write(' * @var string')->write(' */')->write('protected $_schema = \'' . $this->getSchema()->getName() . '\';')->write('')->write('/**')->write(' * @var string')->write(' */')->write('protected $_name = \'' . $this->getRawTableName() . '\';')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getDocument()->getConfig()->get(Formatter::CFG_GENERATE_DRI)) { $_this->writeDependencies($writer); } })->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeReferences($writer); })->outdent()->write('}')->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal() && !$this->isManyToMany()) { // $this->getModelName() return singular form with correct camel case // $this->getRawTableName() return original form with no camel case $writer->open($this->getTableFileName())->write('<?php namespace ' . $this->getNamespace() . ';')->write('')->write('use Illuminate\\Database\\Eloquent\\Model;')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_PHP))->write(''); } })->write('class ' . $this->getModelName() . ' extends ' . $this->getParentTable())->write('{')->indent()->write('/**')->write(' * The database table used by the model.')->write(' * ')->write(' * @var string')->write(' */')->write('protected $table = \'' . $this->getRawTableName() . '\';')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_GENERATE_FILLABLE)) { $_this->writeFillable($writer); } })->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeRelationships($writer); })->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeReferences($writer); })->outdent()->write('}')->write('')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }
protected function writeEntity(WriterInterface $writer) { $this->getDocument()->addLog(sprintf('Writing table "%s"', $this->getModelName())); $namespace = $this->getEntityNamespace(); if ($repositoryNamespace = $this->getConfig()->get(Formatter::CFG_REPOSITORY_NAMESPACE)) { $repositoryNamespace .= '\\'; } $skipGetterAndSetter = $this->getConfig()->get(Formatter::CFG_SKIP_GETTER_SETTER); $serializableEntity = $this->getConfig()->get(Formatter::CFG_GENERATE_ENTITY_SERIALIZATION); $extendableEntity = $this->getConfig()->get(Formatter::CFG_GENERATE_EXTENDABLE_ENTITY); $lifecycleCallbacks = $this->getLifecycleCallbacks(); $extendsClass = $this->getClassToExtend(); $implementsInterface = $this->getInterfaceToImplement(); $comment = $this->getComment(); $writer->open($this->getClassFileName($extendableEntity ? true : false))->write('<?php')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_PHP))->write(''); } })->write('namespace %s;', $namespace)->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeUsedClasses($writer); })->write('/**')->write(' * ' . $this->getNamespace(null, false))->write(' *')->writeIf($comment, $comment)->write(' * ' . $this->getAnnotation('Entity', array('repositoryClass' => $this->getConfig()->get(Formatter::CFG_AUTOMATIC_REPOSITORY) ? $repositoryNamespace . $this->getModelName() . 'Repository' : null)))->write(' * ' . $this->getAnnotation('Table', array('name' => $this->quoteIdentifier($this->getRawTableName()), 'indexes' => $this->getIndexesAnnotation('Index'), 'uniqueConstraints' => $this->getIndexesAnnotation('UniqueConstraint'))))->writeIf($extendableEntity, ' * ' . $this->getAnnotation('InheritanceType', array('SINGLE_TABLE')))->writeIf($extendableEntity, ' * ' . $this->getAnnotation('DiscriminatorColumn', $this->getInheritanceDiscriminatorColumn()))->writeIf($extendableEntity, ' * ' . $this->getAnnotation('DiscriminatorMap', array($this->getInheritanceDiscriminatorMap())))->writeIf($lifecycleCallbacks, ' * @HasLifecycleCallbacks')->write(' */')->write('class ' . $this->getClassName($extendableEntity) . $extendsClass . $implementsInterface)->write('{')->indent()->writeCallback(function (WriterInterface $writer, Table $_this = null) use($skipGetterAndSetter, $serializableEntity, $lifecycleCallbacks) { $_this->writePreClassHandler($writer); $_this->writeVars($writer); $_this->writeConstructor($writer); if (!$skipGetterAndSetter) { $_this->writeGetterAndSetter($writer); } $_this->writePostClassHandler($writer); foreach ($lifecycleCallbacks as $callback => $handlers) { foreach ($handlers as $handler) { $writer->write('/**')->write(' * @%s', ucfirst($callback))->write(' */')->write('public function %s()', $handler)->write('{')->write('}')->write(''); } } if ($serializableEntity) { $_this->writeSerialization($writer); } })->outdent()->write('}')->close(); if ($extendableEntity && !$writer->getStorage()->hasFile($this->getClassFileName())) { $writer->open($this->getClassFileName())->write('<?php')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) { $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_PHP))->write(''); } })->write('namespace %s;', $namespace)->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeExtendedUsedClasses($writer); })->write('/**')->write(' * ' . $this->getNamespace(null, false))->write(' *')->write(' * ' . $this->getAnnotation('Entity', array('repositoryClass' => $this->getConfig()->get(Formatter::CFG_AUTOMATIC_REPOSITORY) ? $repositoryNamespace . $this->getModelName() . 'Repository' : null)))->write(' */')->write('class %s extends %s', $this->getClassName(), $this->getClassName(true))->write('{')->write('}')->close(); } }
public function writeTableOk(WriterInterface $writer) { $namespace = $this->getEntityNamespace(); if ($repositoryNamespace = $this->getDocument()->getConfig()->get(Formatter::CFG_REPOSITORY_NAMESPACE)) { $repositoryNamespace .= '\\'; } $skipGetterAndSetter = $this->getDocument()->getConfig()->get(Formatter::CFG_SKIP_GETTER_SETTER); $serializableEntity = $this->getDocument()->getConfig()->get(Formatter::CFG_GENERATE_ENTITY_SERIALIZATION); $lifecycleCallbacks = $this->getLifecycleCallbacks(); $comment = $this->getComment(); $writer->open($this->getTableFileName())->write('<?php')->write('')->write('namespace %s;', $namespace)->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeUsedClasses($writer); })->write('/**')->write(' * ' . $this->getNamespace(null, false))->write(' *')->writeIf($comment, $comment)->write(' * ' . $this->getAnnotation('Entity', array('repositoryClass' => $this->getDocument()->getConfig()->get(Formatter::CFG_AUTOMATIC_REPOSITORY) ? $repositoryNamespace . $this->getModelName() . 'Repository' : null)))->write(' * ' . $this->getAnnotation('Table', array('name' => $this->quoteIdentifier($this->getRawTableName()), 'indexes' => $this->getIndexesAnnotation(), 'uniqueConstraints' => $this->getUniqueConstraintsAnnotation())))->writeIf($lifecycleCallbacks, ' * @HasLifecycleCallbacks')->write(' */')->write('class ' . $this->getModelName() . (($implements = $this->getClassImplementations()) ? ' implements ' . $implements : ''))->write('{')->indent()->writeCallback(function (WriterInterface $writer, Table $_this = null) use($skipGetterAndSetter, $serializableEntity, $lifecycleCallbacks) { $_this->writePreClassHandler($writer); $_this->getColumns()->write($writer); $_this->writeManyToMany($writer); $_this->writeConstructor($writer); if (!$skipGetterAndSetter) { $_this->getColumns()->writeGetterAndSetter($writer); $_this->writeManyToManyGetterAndSetter($writer); } $_this->writePostClassHandler($writer); foreach ($lifecycleCallbacks as $callback => $handlers) { foreach ($handlers as $handler) { $writer->write('/**')->write(' * @%s', ucfirst($callback))->write(' */')->write('public function %s()', $handler)->write('{')->write('}')->write(''); } } if ($serializableEntity) { $_this->writeSerialization($writer); } })->outdent()->write('}')->close(); }
public function writeTable(WriterInterface $writer) { if (!$this->isExternal()) { if (strpos($this->quoteIdentifier($this->getRawTableName()), '_2_') !== false) { return self::WRITE_M2M; } $namespace = $this->getEntityNamespace(); if ($repositoryNamespace = $this->getDocument()->getConfig()->get(Formatter::CFG_REPOSITORY_NAMESPACE)) { $base = $this->getDocument()->getConfig()->get(Formatter::CFG_BUNDELE_NAMESPACE_TO); $repositoryNamespace = $base . '\\' . $repositoryNamespace . '\\'; } $skipGetterAndSetter = $this->getDocument()->getConfig()->get(Formatter::CFG_SKIP_GETTER_SETTER); $serializableEntity = $this->getDocument()->getConfig()->get(Formatter::CFG_GENERATE_ENTITY_SERIALIZATION); $toArrrabeEntity = $this->getDocument()->getConfig()->get(Formatter::CFG_GENERATE_ENTITY_TO_ARRAY); $lifecycleCallbacks = $this->getLifecycleCallbacks(); $comment = $this->getComment(); $writer->open($this->getTableFileName())->write('<?php')->write('')->write('namespace %s;', $namespace)->writeCallback(function (WriterInterface $writer, Table $_this = null) { $_this->writeUsedClasses($writer); })->write('/**')->write(' *')->writeIf($comment, $comment)->write(' * ' . $this->getAnnotation('Table', array('name' => $this->quoteIdentifier($this->getRawTableName()), 'indexes' => $this->getIndexesAnnotation(), 'uniqueConstraints' => $this->getUniqueConstraintsAnnotation())))->write(' * ' . $this->getAnnotation('Entity', array('repositoryClass' => $this->getDocument()->getConfig()->get(Formatter::CFG_AUTOMATIC_REPOSITORY) ? $repositoryNamespace . $this->getModelName() . 'Repository' : null)))->writeIf($lifecycleCallbacks, ' * @ORM\\HasLifecycleCallbacks')->write(' */')->write('class ' . $this->getModelName() . (($implements = $this->getClassImplementations()) ? ' implements ' . $implements : ''))->write('{')->indent()->writeCallback(function (WriterInterface $writer, Table $_this = null) use($skipGetterAndSetter, $serializableEntity, $toArrrabeEntity, $lifecycleCallbacks) { $_this->writePreClassHandler($writer); $_this->getColumns()->write($writer); $_this->writeManyToMany($writer); $_this->writeConstructor($writer); if (!$skipGetterAndSetter) { $_this->getColumns()->writeGetterAndSetter($writer); $_this->writeManyToManyGetterAndSetter($writer); } $_this->writePostClassHandler($writer); foreach ($lifecycleCallbacks as $callback => $handlers) { foreach ($handlers as $handler) { $writer->write('/**')->write(' * @ORM\\%s', ucfirst($callback))->write(' * @throws \\Symfony\\Component\\Intl\\Exception\\MethodNotImplementedException')->write(' */')->write('public function %s()', $handler)->write('{')->indent()->write('throw new \\Symfony\\Component\\Intl\\Exception\\MethodNotImplementedException(__METHOD__);')->outdent()->write('}')->write(''); } } if ($serializableEntity) { $_this->writeSerialization($writer); } if ($toArrrabeEntity) { $_this->writeToArray($writer); } $_this->writeIdSetGet($writer); $_this->writeIsNew($writer); $_this->writeToString($writer); })->outdent()->write('}')->close(); return self::WRITE_OK; } return self::WRITE_EXTERNAL; }