Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

84 lines (68 sloc) 3.375 kB
* This file is part of the Doctrine MongoDBBundle
* The code was originally distributed inside the Symfony framework.
* (c) Fabien Potencier <>
* (c) Doctrine Project
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
namespace Doctrine\Bundle\MongoDBBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
* Generate document classes from mapping information
* @author Fabien Potencier <>
* @author Jonathan H. Wage <>
class GenerateDocumentsDoctrineODMCommand extends DoctrineODMCommand
protected function configure()
->setDescription('Generate document classes and method stubs from your mapping information.')
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to initialize the document or documents in.')
->addOption('document', null, InputOption::VALUE_OPTIONAL, 'The document class to initialize (shortname without namespace).')
The <info>doctrine:mongodb:generate:documents</info> command generates document classes and method stubs from your mapping information:
You have to limit generation of documents to an individual bundle:
<info>./app/console doctrine:mongodb:generate:documents MyCustomBundle</info>
Alternatively, you can limit generation to a single document within a bundle:
<info>./app/console doctrine:mongodb:generate:documents "MyCustomBundle" --document="User"</info>
You have to specify the shortname (without namespace) of the document you want to filter for.
protected function execute(InputInterface $input, OutputInterface $output)
$bundleName = $input->getArgument('bundle');
$filterDocument = $input->getOption('document');
$foundBundle = $this->findBundle($bundleName);
if ($metadatas = $this->getBundleMetadatas($foundBundle)) {
$output->writeln(sprintf('Generating documents for "<info>%s</info>"', $foundBundle->getName()));
$documentGenerator = $this->getDocumentGenerator();
foreach ($metadatas as $metadata) {
if ($filterDocument && $metadata->reflClass->getShortName() != $filterDocument) {
if (strpos($metadata->name, $foundBundle->getNamespace()) === false) {
throw new \RuntimeException(
"Document " . $metadata->name . " and bundle don't have a common namespace, ".
"generation failed because the target directory cannot be detected.");
$output->writeln(sprintf(' > generating <comment>%s</comment>', $metadata->name));
$documentGenerator->generate(array($metadata), $this->findBasePathForBundle($foundBundle));
} else {
throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped documents.");
Jump to Line
Something went wrong with that request. Please try again.