Skip to content

Commit

Permalink
Implements some options that already exist on other doctrine-related …
Browse files Browse the repository at this point in the history
…commands
  • Loading branch information
mcbennn committed May 25, 2011
1 parent 1798644 commit 6504797
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Expand Up @@ -32,6 +32,8 @@ protected function configure()
->setDescription('Generate entity classes and method stubs from your mapping information')
->addArgument('name', InputArgument::REQUIRED, 'A bundle name, a namespace, or a class name')
->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path where to generate entities when it cannot be guessed')
->addOption('force', null, InputOption::VALUE_NONE, 'Force to overwrite existing entities files.')
->addOption('annotate', null, InputOption::VALUE_NONE, 'Should we annotate generated entity classes')
->setHelp(<<<EOT
The <info>doctrine:generate:entities</info> command generates entity classes
and method stubs from your mapping information:
Expand All @@ -57,6 +59,16 @@ protected function configure()
<info>./app/console doctrine:generate:entities Blog/Entity --path=src/</info>
You should provide the <comment>--force</comment> option if you dont mind to back up files
before to generate entities:
<info>./app/console doctrine:generate:entities Blog/Entity --force</info>
If you want that generated entity classes are annotated with ORM mapping,
you can provide the <comment>--annotate</comment> option:
<info>./app/console doctrine:generate:entities Blog/Entity --annotate</info>
EOT
);
}
Expand Down Expand Up @@ -85,6 +97,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$generator = $this->getEntityGenerator();
$generator->setGenerateAnnotations(($input->getOption('annotate') !== false));
$generator->setBackupExisting(($input->getOption('force') === true));
$repoGenerator = new EntityRepositoryGenerator();
foreach ($metadatas as $metadata) {
$output->writeln(sprintf(' > generating <comment>%s</comment>', $metadata->name));
Expand Down
Expand Up @@ -18,6 +18,7 @@
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use Doctrine\ORM\Tools\Console\MetadataFilter;

/**
* Import Doctrine ORM metadata mapping information from an existing database.
Expand All @@ -34,6 +35,8 @@ protected function configure()
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to import the mapping information to')
->addArgument('mapping-type', InputArgument::OPTIONAL, 'The mapping type to export the imported mapping information to')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be mapped.')
->addOption('force', null, InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
->setDescription('Import mapping information from an existing database')
->setHelp(<<<EOT
The <info>doctrine:mapping:import</info> command imports mapping information
Expand All @@ -45,6 +48,16 @@ protected function configure()
<info>--em</info> option:
<info>./app/console doctrine:mapping:import "MyCustomBundle" xml --em=default</info>
If you dont want to map every entity that can be found in the database, use the
<info>--filter</info> option. It will try to match the targetted mapped entity with the
provided pattern string.
<info>./app/console doctrine:mapping:import "MyCustomBundle" xml --filter=MyMatchedEntity</info>
Use the <info>--force</info> option, if you want to override existing mapping files:
<info>./app/console doctrine:mapping:import "MyCustomBundle" xml --force</info>
EOT
);
}
Expand All @@ -66,6 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$cme = new ClassMetadataExporter();
$exporter = $cme->getExporter($type);
$exporter->setOverwriteExistingFiles(($input->getOption('force') !== false));

if ('annotation' === $type) {
$entityGenerator = $this->getEntityGenerator();
Expand All @@ -83,6 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
$metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
if ($metadata) {
$output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
foreach ($metadata as $class) {
Expand Down

0 comments on commit 6504797

Please sign in to comment.