Commit 700060cf authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-510 Refactored all Command Tools to use ClassMetadataFactory instead of ClassMetadataReader

parent 6e5b1bbe
...@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command; ...@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Components\Console,
Doctrine\ORM\Tools\Export\ClassMetadataExporter,
Doctrine\ORM\Tools\ConvertDoctrine1Schema;
/** /**
* Command to convert a Doctrine 1 schema to a Doctrine 2 mapping file. * Command to convert a Doctrine 1 schema to a Doctrine 2 mapping file.
......
...@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command; ...@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Components\Console,
Doctrine\ORM\Tools\Console\MetadataFilter,
Doctrine\ORM\Tools\Export\ClassMetadataExporter;
/** /**
* Command to convert your mapping information between the various formats. * Command to convert your mapping information between the various formats.
...@@ -48,8 +50,9 @@ class ConvertMappingCommand extends Console\Command\Command ...@@ -48,8 +50,9 @@ class ConvertMappingCommand extends Console\Command\Command
->setName('orm:convert-mapping') ->setName('orm:convert-mapping')
->setDescription('Convert mapping information between supported formats.') ->setDescription('Convert mapping information between supported formats.')
->setDefinition(array( ->setDefinition(array(
new InputArgument( new InputOption(
'from-path', InputArgument::REQUIRED, 'The path of mapping information.' 'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(
'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.' 'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.'
...@@ -58,10 +61,8 @@ class ConvertMappingCommand extends Console\Command\Command ...@@ -58,10 +61,8 @@ class ConvertMappingCommand extends Console\Command\Command
'dest-path', InputArgument::REQUIRED, 'dest-path', InputArgument::REQUIRED,
'The path to generate your entities classes.' 'The path to generate your entities classes.'
), ),
new InputOption( new InputArgument(
'from', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'from-database', InputArgument::OPTIONAL, 'The path of mapping information.'
'Optional paths of mapping information.',
array()
), ),
new InputOption( new InputOption(
'extend', null, InputOption::PARAMETER_OPTIONAL, 'extend', null, InputOption::PARAMETER_OPTIONAL,
...@@ -84,37 +85,16 @@ EOT ...@@ -84,37 +85,16 @@ EOT
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{ {
$em = $this->getHelper('em')->getEntityManager(); $em = $this->getHelper('em')->getEntityManager();
$cme = new ClassMetadataExporter();
// Process source directories
$fromPath = $input->getArgument('from-path');
if (strtolower($fromPath) !== 'database') {
$fromPaths = array_merge(array($fromPath), $input->getOption('from'));
foreach ($fromPaths as &$dirName) { $metadatas = $em->getMetadataFactory()->getAllMetadata();
$dirName = realpath($dirName); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
if ( ! file_exists($dirName)) { if ($input->getArgument('from-database') === true) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not exist.", $dirName)
);
} else if ( ! is_readable($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not have read permissions.", $dirName)
);
}
$cme->addMappingSource($dirName);
}
} else {
$em->getConfiguration()->setMetadataDriverImpl( $em->getConfiguration()->setMetadataDriverImpl(
new \Doctrine\ORM\Mapping\Driver\DatabaseDriver( new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
$em->getConnection()->getSchemaManager() $em->getConnection()->getSchemaManager()
) )
); );
$cme->addMappingSource($fromPath);
} }
// Process destination directory // Process destination directory
...@@ -132,6 +112,7 @@ EOT ...@@ -132,6 +112,7 @@ EOT
$toType = strtolower($input->getArgument('to-type')); $toType = strtolower($input->getArgument('to-type'));
$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($toType, $destPath); $exporter = $cme->getExporter($toType, $destPath);
if ($toType == 'annotation') { if ($toType == 'annotation') {
...@@ -145,9 +126,7 @@ EOT ...@@ -145,9 +126,7 @@ EOT
} }
} }
$metadatas = $cme->getMetadatas(); if (count($metadatas)) {
if ($metadatas) {
foreach ($metadatas as $metadata) { foreach ($metadatas as $metadata) {
$output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL); $output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
} }
...@@ -156,7 +135,7 @@ EOT ...@@ -156,7 +135,7 @@ EOT
$exporter->export(); $exporter->export();
$output->write(PHP_EOL . sprintf( $output->write(PHP_EOL . sprintf(
'Exporting "<info>%s</info>" mapping information to "<info>%s</info>"', $toType, $destPath 'Exporting "<info>%s</info>" mapping information to "<info>%s</info>"' . PHP_EOL, $toType, $destPath
)); ));
} else { } else {
$output->write('No Metadata Classes to process.' . PHP_EOL); $output->write('No Metadata Classes to process.' . PHP_EOL);
......
...@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command; ...@@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Components\Console,
Doctrine\ORM\Tools\Console\MetadataFilter,
Doctrine\ORM\Tools\EntityGenerator;
/** /**
* Command to generate entity classes and method stubs from your mapping information. * Command to generate entity classes and method stubs from your mapping information.
...@@ -48,17 +50,13 @@ class GenerateEntitiesCommand extends Console\Command\Command ...@@ -48,17 +50,13 @@ class GenerateEntitiesCommand extends Console\Command\Command
->setName('orm:generate-entities') ->setName('orm:generate-entities')
->setDescription('Generate entity classes and method stubs from your mapping information.') ->setDescription('Generate entity classes and method stubs from your mapping information.')
->setDefinition(array( ->setDefinition(array(
new InputArgument( new InputOption(
'from-path', InputArgument::REQUIRED, 'The path of mapping information.' 'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(
'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.' 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.'
), ),
new InputOption(
'from', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'Optional paths of mapping information.',
array()
),
new InputOption( new InputOption(
'generate-annotations', null, InputOption::PARAMETER_OPTIONAL, 'generate-annotations', null, InputOption::PARAMETER_OPTIONAL,
'Flag to define if generator should generate annotation metadata on entities.', false 'Flag to define if generator should generate annotation metadata on entities.', false
...@@ -96,29 +94,10 @@ EOT ...@@ -96,29 +94,10 @@ EOT
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{ {
$em = $this->getHelper('em')->getEntityManager(); $em = $this->getHelper('em')->getEntityManager();
$reader = new ClassMetadataReader(); $metadatas = $em->getMetadataFactory()->getAllMetadata();
$reader->setEntityManager($em); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process source directories
$fromPaths = array_merge(array($input->getArgument('from-path')), $input->getOption('from'));
foreach ($fromPaths as $dirName) {
$dirName = realpath($dirName);
if ( ! file_exists($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not exist.", $dirName)
);
} else if ( ! is_readable($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not have read permissions.", $dirName)
);
}
$reader->addMappingSource($dirName);
}
// Process destination directory // Process destination directory
$destPath = realpath($input->getArgument('dest-path')); $destPath = realpath($input->getArgument('dest-path'));
...@@ -132,23 +111,20 @@ EOT ...@@ -132,23 +111,20 @@ EOT
); );
} }
// Create EntityGenerator if ( count($metadatas)) {
$entityGenerator = new EntityGenerator(); // Create EntityGenerator
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
$entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
$entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
if (($extend = $input->getOption('extend')) !== null) { $entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
$entityGenerator->setClassToExtend($extend); $entityGenerator->setGenerateStubMethods($input->getOption('generate-methods'));
} $entityGenerator->setRegenerateEntityIfExists($input->getOption('regenerate-entities'));
$entityGenerator->setUpdateEntityIfExists($input->getOption('update-entities'));
$entityGenerator->setNumSpaces($input->getOption('num-spaces'));
// Retrieving ClassMetadatas if (($extend = $input->getOption('extend')) !== null) {
$metadatas = $reader->getMetadatas(); $entityGenerator->setClassToExtend($extend);
}
if ( ! empty($metadatas)) {
foreach ($metadatas as $metadata) { foreach ($metadatas as $metadata) {
$output->write( $output->write(
sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL
......
...@@ -23,7 +23,8 @@ namespace Doctrine\ORM\Tools\Console\Command; ...@@ -23,7 +23,8 @@ namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Components\Console,
Doctrine\ORM\Tools\Console\MetadataFilter;
/** /**
* Command to (re)generate the proxy classes used by doctrine. * Command to (re)generate the proxy classes used by doctrine.
...@@ -48,18 +49,14 @@ class GenerateProxiesCommand extends Console\Command\Command ...@@ -48,18 +49,14 @@ class GenerateProxiesCommand extends Console\Command\Command
->setName('orm:generate-proxies') ->setName('orm:generate-proxies')
->setDescription('Generates proxy classes for entity classes.') ->setDescription('Generates proxy classes for entity classes.')
->setDefinition(array( ->setDefinition(array(
new InputArgument( new InputOption(
'from-path', InputArgument::REQUIRED, 'The path of mapping information.' 'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(
'dest-path', InputArgument::OPTIONAL, 'dest-path', InputArgument::OPTIONAL,
'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.' 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.'
), ),
new InputOption(
'from', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'Optional paths of mapping information.',
array()
)
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
Generates proxy classes for entity classes. Generates proxy classes for entity classes.
...@@ -73,28 +70,9 @@ EOT ...@@ -73,28 +70,9 @@ EOT
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{ {
$em = $this->getHelper('em')->getEntityManager(); $em = $this->getHelper('em')->getEntityManager();
$reader = new ClassMetadataReader(); $metadatas = $em->getMetadataFactory()->getAllMetadata();
$reader->setEntityManager($em); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process source directories
$fromPaths = array_merge(array($input->getArgument('from-path')), $input->getOption('from'));
foreach ($fromPaths as $dirName) {
$dirName = realpath($dirName);
if ( ! file_exists($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not exist.", $dirName)
);
} else if ( ! is_readable($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not have read permissions.", $dirName)
);
}
$reader->addMappingSource($dirName);
}
// Process destination directory // Process destination directory
if (($destPath = $input->getArgument('dest-path')) === null) { if (($destPath = $input->getArgument('dest-path')) === null) {
...@@ -113,10 +91,7 @@ EOT ...@@ -113,10 +91,7 @@ EOT
); );
} }
// Retrieving ClassMetadatas if ( count($metadatas)) {
$metadatas = $reader->getMetadatas();
if ( ! empty($metadatas)) {
foreach ($metadatas as $metadata) { foreach ($metadatas as $metadata) {
$output->write( $output->write(
sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL
......
...@@ -23,7 +23,8 @@ namespace Doctrine\ORM\Tools\Console\Command; ...@@ -23,7 +23,8 @@ namespace Doctrine\ORM\Tools\Console\Command;
use Symfony\Components\Console\Input\InputArgument, use Symfony\Components\Console\Input\InputArgument,
Symfony\Components\Console\Input\InputOption, Symfony\Components\Console\Input\InputOption,
Symfony\Components\Console; Symfony\Components\Console,
Doctrine\ORM\Tools\Console\MetadataFilter;
/** /**
* Command to generate repository classes for mapping information. * Command to generate repository classes for mapping information.
...@@ -65,16 +66,12 @@ class <className> extends EntityRepository ...@@ -65,16 +66,12 @@ class <className> extends EntityRepository
->setName('orm:generate-repositories') ->setName('orm:generate-repositories')
->setDescription('Generate repository classes from your mapping information.') ->setDescription('Generate repository classes from your mapping information.')
->setDefinition(array( ->setDefinition(array(
new InputArgument( new InputOption(
'from-path', InputArgument::REQUIRED, 'The path of mapping information.' 'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(
'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.' 'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.'
),
new InputOption(
'from', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
'Optional paths of mapping information.',
array()
) )
)) ))
->setHelp(<<<EOT ->setHelp(<<<EOT
...@@ -89,28 +86,9 @@ EOT ...@@ -89,28 +86,9 @@ EOT
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{ {
$em = $this->getHelper('em')->getEntityManager(); $em = $this->getHelper('em')->getEntityManager();
$reader = new ClassMetadataReader(); $metadatas = $em->getMetadataFactory()->getAllMetadata();
$reader->setEntityManager($em); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
// Process source directories
$fromPaths = array_merge(array($input->getArgument('from-path')), $input->getOption('from'));
foreach ($fromPaths as $dirName) {
$dirName = realpath($dirName);
if ( ! file_exists($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not exist.", $dirName)
);
} else if ( ! is_readable($dirName)) {
throw new \InvalidArgumentException(
sprintf("Mapping directory '<info>%s</info>' does not have read permissions.", $dirName)
);
}
$reader->addMappingSource($dirName);
}
// Process destination directory // Process destination directory
$destPath = realpath($input->getArgument('dest-path')); $destPath = realpath($input->getArgument('dest-path'));
...@@ -125,10 +103,7 @@ EOT ...@@ -125,10 +103,7 @@ EOT
); );
} }
// Retrieving ClassMetadatas if ( count($metadatas)) {
$metadatas = $reader->getMetadatas();
if ( ! empty($metadatas)) {
$numRepositories = 0; $numRepositories = 0;
foreach ($metadatas as $metadata) { foreach ($metadatas as $metadata) {
......
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