DDC-510 Refactored all Command Tools to use ClassMetadataFactory instead of ClassMetadataReader
This commit is contained in:
parent
6e5b1bbe60
commit
700060cfb2
5 changed files with 56 additions and 149 deletions
|
@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command;
|
|||
|
||||
use Symfony\Components\Console\Input\InputArgument,
|
||||
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.
|
||||
|
|
|
@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command;
|
|||
|
||||
use Symfony\Components\Console\Input\InputArgument,
|
||||
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.
|
||||
|
@ -48,8 +50,9 @@ class ConvertMappingCommand extends Console\Command\Command
|
|||
->setName('orm:convert-mapping')
|
||||
->setDescription('Convert mapping information between supported formats.')
|
||||
->setDefinition(array(
|
||||
new InputArgument(
|
||||
'from-path', InputArgument::REQUIRED, 'The path of mapping information.'
|
||||
new InputOption(
|
||||
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.'
|
||||
|
@ -58,10 +61,8 @@ class ConvertMappingCommand extends Console\Command\Command
|
|||
'dest-path', InputArgument::REQUIRED,
|
||||
'The path to generate your entities classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'from', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
|
||||
'Optional paths of mapping information.',
|
||||
array()
|
||||
new InputArgument(
|
||||
'from-database', InputArgument::OPTIONAL, 'The path of mapping information.'
|
||||
),
|
||||
new InputOption(
|
||||
'extend', null, InputOption::PARAMETER_OPTIONAL,
|
||||
|
@ -84,37 +85,16 @@ EOT
|
|||
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$cme = new ClassMetadataExporter();
|
||||
|
||||
// Process source directories
|
||||
$fromPath = $input->getArgument('from-path');
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
|
||||
|
||||
if (strtolower($fromPath) !== 'database') {
|
||||
$fromPaths = array_merge(array($fromPath), $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)
|
||||
);
|
||||
}
|
||||
|
||||
$cme->addMappingSource($dirName);
|
||||
}
|
||||
} else {
|
||||
if ($input->getArgument('from-database') === true) {
|
||||
$em->getConfiguration()->setMetadataDriverImpl(
|
||||
new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
|
||||
$em->getConnection()->getSchemaManager()
|
||||
)
|
||||
);
|
||||
|
||||
$cme->addMappingSource($fromPath);
|
||||
}
|
||||
|
||||
// Process destination directory
|
||||
|
@ -132,6 +112,7 @@ EOT
|
|||
|
||||
$toType = strtolower($input->getArgument('to-type'));
|
||||
|
||||
$cme = new ClassMetadataExporter();
|
||||
$exporter = $cme->getExporter($toType, $destPath);
|
||||
|
||||
if ($toType == 'annotation') {
|
||||
|
@ -145,9 +126,7 @@ EOT
|
|||
}
|
||||
}
|
||||
|
||||
$metadatas = $cme->getMetadatas();
|
||||
|
||||
if ($metadatas) {
|
||||
if (count($metadatas)) {
|
||||
foreach ($metadatas as $metadata) {
|
||||
$output->write(sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL);
|
||||
}
|
||||
|
@ -156,7 +135,7 @@ EOT
|
|||
$exporter->export();
|
||||
|
||||
$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 {
|
||||
$output->write('No Metadata Classes to process.' . PHP_EOL);
|
||||
|
|
|
@ -23,7 +23,9 @@ namespace Doctrine\ORM\Tools\Console\Command;
|
|||
|
||||
use Symfony\Components\Console\Input\InputArgument,
|
||||
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.
|
||||
|
@ -48,17 +50,13 @@ class GenerateEntitiesCommand extends Console\Command\Command
|
|||
->setName('orm:generate-entities')
|
||||
->setDescription('Generate entity classes and method stubs from your mapping information.')
|
||||
->setDefinition(array(
|
||||
new InputArgument(
|
||||
'from-path', InputArgument::REQUIRED, 'The path of mapping information.'
|
||||
new InputOption(
|
||||
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'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(
|
||||
'generate-annotations', null, InputOption::PARAMETER_OPTIONAL,
|
||||
'Flag to define if generator should generate annotation metadata on entities.', false
|
||||
|
@ -96,29 +94,10 @@ EOT
|
|||
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$reader = new ClassMetadataReader();
|
||||
$reader->setEntityManager($em);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
|
||||
|
||||
// Process destination directory
|
||||
$destPath = realpath($input->getArgument('dest-path'));
|
||||
|
||||
|
@ -132,23 +111,20 @@ EOT
|
|||
);
|
||||
}
|
||||
|
||||
// Create EntityGenerator
|
||||
$entityGenerator = new EntityGenerator();
|
||||
if ( count($metadatas)) {
|
||||
// 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'));
|
||||
$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->setClassToExtend($extend);
|
||||
}
|
||||
if (($extend = $input->getOption('extend')) !== null) {
|
||||
$entityGenerator->setClassToExtend($extend);
|
||||
}
|
||||
|
||||
// Retrieving ClassMetadatas
|
||||
$metadatas = $reader->getMetadatas();
|
||||
|
||||
if ( ! empty($metadatas)) {
|
||||
foreach ($metadatas as $metadata) {
|
||||
$output->write(
|
||||
sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL
|
||||
|
|
|
@ -23,7 +23,8 @@ namespace Doctrine\ORM\Tools\Console\Command;
|
|||
|
||||
use Symfony\Components\Console\Input\InputArgument,
|
||||
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.
|
||||
|
@ -48,18 +49,14 @@ class GenerateProxiesCommand extends Console\Command\Command
|
|||
->setName('orm:generate-proxies')
|
||||
->setDescription('Generates proxy classes for entity classes.')
|
||||
->setDefinition(array(
|
||||
new InputArgument(
|
||||
'from-path', InputArgument::REQUIRED, 'The path of mapping information.'
|
||||
new InputOption(
|
||||
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'dest-path', InputArgument::OPTIONAL,
|
||||
'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
|
||||
Generates proxy classes for entity classes.
|
||||
|
@ -73,28 +70,9 @@ EOT
|
|||
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$reader = new ClassMetadataReader();
|
||||
$reader->setEntityManager($em);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
|
||||
|
||||
// Process destination directory
|
||||
if (($destPath = $input->getArgument('dest-path')) === null) {
|
||||
|
@ -113,10 +91,7 @@ EOT
|
|||
);
|
||||
}
|
||||
|
||||
// Retrieving ClassMetadatas
|
||||
$metadatas = $reader->getMetadatas();
|
||||
|
||||
if ( ! empty($metadatas)) {
|
||||
if ( count($metadatas)) {
|
||||
foreach ($metadatas as $metadata) {
|
||||
$output->write(
|
||||
sprintf('Processing entity "<info>%s</info>"', $metadata->name) . PHP_EOL
|
||||
|
|
|
@ -23,7 +23,8 @@ namespace Doctrine\ORM\Tools\Console\Command;
|
|||
|
||||
use Symfony\Components\Console\Input\InputArgument,
|
||||
Symfony\Components\Console\Input\InputOption,
|
||||
Symfony\Components\Console;
|
||||
Symfony\Components\Console,
|
||||
Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
|
||||
/**
|
||||
* Command to generate repository classes for mapping information.
|
||||
|
@ -65,16 +66,12 @@ class <className> extends EntityRepository
|
|||
->setName('orm:generate-repositories')
|
||||
->setDescription('Generate repository classes from your mapping information.')
|
||||
->setDefinition(array(
|
||||
new InputArgument(
|
||||
'from-path', InputArgument::REQUIRED, 'The path of mapping information.'
|
||||
new InputOption(
|
||||
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'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
|
||||
|
@ -89,28 +86,9 @@ EOT
|
|||
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$reader = new ClassMetadataReader();
|
||||
$reader->setEntityManager($em);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
|
||||
|
||||
// Process destination directory
|
||||
$destPath = realpath($input->getArgument('dest-path'));
|
||||
|
@ -125,10 +103,7 @@ EOT
|
|||
);
|
||||
}
|
||||
|
||||
// Retrieving ClassMetadatas
|
||||
$metadatas = $reader->getMetadatas();
|
||||
|
||||
if ( ! empty($metadatas)) {
|
||||
if ( count($metadatas)) {
|
||||
$numRepositories = 0;
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
|
|
Loading…
Add table
Reference in a new issue