Commit f34a99cc authored by jwage's avatar jwage

[2.0] Fixing hardcoded dependency to EntityGenerator

parent 65536142
......@@ -26,7 +26,8 @@ use Doctrine\Common\Cli\Tasks\AbstractTask,
Doctrine\Common\Cli\CliException,
Doctrine\Common\Cli\Option,
Doctrine\Common\Cli\OptionGroup,
Doctrine\ORM\Tools\ConvertDoctrine1Schema;
Doctrine\ORM\Tools\ConvertDoctrine1Schema,
Doctrine\ORM\Tools\EntityGenerator;
/**
* CLI Task to convert a Doctrine 1 schema to a Doctrine 2 mapping file
......@@ -90,6 +91,11 @@ class ConvertDoctrine1SchemaTask extends AbstractTask
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($arguments['to'], $arguments['dest']);
if ($arguments['to'] === 'annotation') {
$entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
}
$converter = new ConvertDoctrine1Schema($arguments['from']);
$metadatas = $converter->getMetadatas();
......
......@@ -120,12 +120,17 @@ class ConvertMappingTask extends AbstractTask
// Get exporter and configure it
$exporter = $cme->getExporter($arguments['to'], $arguments['dest']);
if (isset($arguments['extend']) && $arguments['extend']) {
$exporter->setClassToExtend($arguments['extend']);
}
if (isset($arguments['num-spaces']) && $arguments['extend']) {
$exporter->setNumSpaces($arguments['num-spaces']);
if ($arguments['to'] === 'annotation') {
$entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
if (isset($arguments['extend']) && $arguments['extend']) {
$entityGenerator->setClassToExtend($arguments['extend']);
}
if (isset($arguments['num-spaces']) && $arguments['extend']) {
$entityGenerator->setNumSpaces($arguments['num-spaces']);
}
}
$from = (array) $arguments['from'];
......
......@@ -83,18 +83,18 @@ class GenerateEntitiesTask extends AbstractTask
$from = $arguments['from'];
$dest = realpath($arguments['dest']);
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(false);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(false);
$generator->setUpdateEntityIfExists(true);
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
if (isset($arguments['extend']) && $arguments['extend']) {
$generator->setClassToExtend($arguments['extend']);
$entityGenerator->setClassToExtend($arguments['extend']);
}
if (isset($arguments['num-spaces']) && $arguments['extend']) {
$generator->setNumSpaces($arguments['num-spaces']);
$entityGenerator->setNumSpaces($arguments['num-spaces']);
}
$reader = new ClassMetadataReader();
......@@ -108,7 +108,7 @@ class GenerateEntitiesTask extends AbstractTask
);
}
$generator->generate($metadatas, $dest);
$entityGenerator->generate($metadatas, $dest);
$printer->writeln('');
$printer->writeln(
......
......@@ -38,13 +38,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
class AnnotationExporter extends AbstractExporter
{
protected $_extension = '.php';
private $_generator;
public function __construct($dir = null)
{
parent::__construct($dir);
$this->_generator = new EntityGenerator();
}
private $_entityGenerator;
/**
* Converts a single ClassMetadata instance to the exported format
......@@ -55,12 +49,12 @@ class AnnotationExporter extends AbstractExporter
*/
public function exportClassMetadata(ClassMetadataInfo $metadata)
{
$this->_generator->setGenerateAnnotations(true);
$this->_generator->setGenerateStubMethods(false);
$this->_generator->setRegenerateEntityIfExists(false);
$this->_generator->setUpdateEntityIfExists(false);
$this->_entityGenerator->setGenerateAnnotations(true);
$this->_entityGenerator->setGenerateStubMethods(false);
$this->_entityGenerator->setRegenerateEntityIfExists(false);
$this->_entityGenerator->setUpdateEntityIfExists(false);
return $this->_generator->generateEntityClass($metadata);
return $this->_entityGenerator->generateEntityClass($metadata);
}
protected function _generateOutputPath(ClassMetadataInfo $metadata)
......@@ -68,24 +62,8 @@ class AnnotationExporter extends AbstractExporter
return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension;
}
/**
* Set the number of spaces the exported class should have
*
* @param integer $numSpaces
* @return void
*/
public function setNumSpaces($numSpaces)
{
$this->_generator->setNumSpaces($numSpaces);
}
/**
* Set the name of the class the generated classes should extend from
*
* @return void
*/
public function setClassToExtend($classToExtend)
public function setEntityGenerator(EntityGenerator $entityGenerator)
{
$this->_generator->setClassToExtend($classToExtend);
$this->_entityGenerator = $entityGenerator;
}
}
\ No newline at end of file
......@@ -22,7 +22,8 @@
namespace Doctrine\Tests\ORM\Tools\Export;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter,
Doctrine\ORM\Mapping\ClassMetadataInfo;
Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Tools\EntityGenerator;
require_once __DIR__ . '/../../../TestInit.php';
......@@ -80,6 +81,10 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
{
$type = $this->_getType();
$exporter = $cme->getExporter($type, __DIR__ . '/export/' . $type);
if ($type === 'annotation') {
$entityGenerator = new EntityGenerator();
$exporter->setEntityGenerator($entityGenerator);
}
$this->_extension = $exporter->getExtension();
$metadatas = $cme->getMetadatas();
if ($type == 'annotation') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment