-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
185 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
|
||
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\OutputInterface; | ||
|
||
/** | ||
* Generate document classes from mapping information | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Jonathan H. Wage <[email protected]> | ||
*/ | ||
class GenerateDocumentsDoctrineODMCommand extends DoctrineODMCommand | ||
{ | ||
protected static $defaultName = 'doctrine:mongodb:generate:documents'; | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->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).') | ||
->addOption('no-backup', null, InputOption::VALUE_NONE, 'Do not backup existing entities files.') | ||
->setHelp(<<<EOT | ||
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>php app/console doctrine:mongodb:generate:documents MyCustomBundle</info> | ||
Alternatively, you can limit generation to a single document within a bundle: | ||
<info>php 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. | ||
By default, the unmodified version of each document is backed up and saved | ||
(e.g. ~Product.php). To prevent this task from creating the backup file, | ||
pass the <comment>--no-backup</comment> option: | ||
<info>php app/console doctrine:mongodb:generate:documents MyCustomBundle --no-backup</info> | ||
EOT | ||
); | ||
} | ||
|
||
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(); | ||
$documentGenerator->setBackupExisting(!$input->getOption('no-backup')); | ||
|
||
foreach ($metadatas as $metadata) { | ||
if ($filterDocument && $metadata->getReflectionClass()->getShortName() != $filterDocument) { | ||
continue; | ||
} | ||
|
||
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([$metadata], $this->findBasePathForBundle($foundBundle)); | ||
} | ||
} else { | ||
throw new \RuntimeException( | ||
"Bundle " . $bundleName . " does not contain any mapped documents.". | ||
"Did you maybe forget to define a mapping configuration?"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
|
||
namespace Doctrine\Bundle\MongoDBBundle\Command; | ||
|
||
use Doctrine\ODM\MongoDB\Tools\DocumentRepositoryGenerator; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Command to generate repository classes for mapping information. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Jonathan H. Wage <[email protected]> | ||
*/ | ||
class GenerateRepositoriesDoctrineODMCommand extends DoctrineODMCommand | ||
{ | ||
protected static $defaultName = 'doctrine:mongodb:generate:repositories'; | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Generate repository classes from your mapping information.') | ||
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to initialize the repositories in.') | ||
->addOption('document', null, InputOption::VALUE_OPTIONAL, 'The document class to generate the repository for (shortname without namespace).') | ||
->setHelp(<<<EOT | ||
The <info>doctrine:mongodb:generate:repositories</info> command generates the configured document repository classes from your mapping information: | ||
<info>./app/console doctrine:mongodb:generate:repositories</info> | ||
EOT | ||
); | ||
} | ||
|
||
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 document repositories for "<info>%s</info>"', $foundBundle->getName())); | ||
$generator = new DocumentRepositoryGenerator(); | ||
|
||
foreach ($metadatas as $metadata) { | ||
if ($filterDocument && $filterDocument !== $metadata->reflClass->getShortname()) { | ||
continue; | ||
} | ||
|
||
if ($metadata->customRepositoryClassName) { | ||
if (strpos($metadata->customRepositoryClassName, $foundBundle->getNamespace()) === false) { | ||
throw new \RuntimeException( | ||
"Repository " . $metadata->customRepositoryClassName . " and bundle don't have a common namespace, ". | ||
"generation failed because the target directory cannot be detected."); | ||
} | ||
|
||
$output->writeln(sprintf(' > <info>OK</info> generating <comment>%s</comment>', $metadata->customRepositoryClassName)); | ||
$generator->writeDocumentRepositoryClass( | ||
$metadata->customRepositoryClassName, | ||
$foundBundle->getPath(), | ||
$foundBundle->getNamespace() | ||
); | ||
} else { | ||
$output->writeln(sprintf(' > <error>SKIP</error> no custom repository for <comment>%s</comment>', $metadata->name)); | ||
} | ||
} | ||
} else { | ||
throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped documents."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters