Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Symfony proxies for Doctrine ODM schema:create and schema:drop co…
…nsole commands.
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php
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,44 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Output\Output; | ||
use Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\CreateCommand; | ||
|
||
/** | ||
* Command to create the database schema for a set of classes based on their mappings. | ||
* | ||
* @author Justin Hileman <justin@shopopensky.com> | ||
*/ | ||
class CreateSchemaDoctrineODMCommand extends CreateCommand | ||
{ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setName('doctrine:odm:schema:create') | ||
->addOption('dm', null, InputOption::PARAMETER_OPTIONAL, 'The document manager to use for this command.') | ||
->setHelp(<<<EOT | ||
The <info>doctrine:odm:schema:create</info> command creates the default document manager's schema: | ||
<info>./symfony doctrine:odm:schema:create</info> | ||
You can also optionally specify the name of a document manager to create the schema for: | ||
<info>./symfony doctrine:odm:schema:create --dm=default</info> | ||
EOT | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
DoctrineODMCommand::setApplicationDocumentManager($this->application, $input->getOption('dm')); | ||
|
||
parent::execute($input, $output); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php
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,29 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\Command; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper; | ||
|
||
/** | ||
* Base class for Doctrine ODM console commands to extend. | ||
* | ||
* @author Justin Hileman <justin@shopopensky.com> | ||
*/ | ||
abstract class DoctrineODMCommand extends Command | ||
{ | ||
public static function setApplicationDocumentManager(Application $application, $dmName) | ||
{ | ||
$container = $application->getKernel()->getContainer(); | ||
$dmName = $dmName ? $dmName : 'default'; | ||
$dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName); | ||
if (!$container->has($dmServiceName)) { | ||
throw new \InvalidArgumentException(sprintf('Could not find Doctrine ODM DocumentManager named "%s"', $dmName)); | ||
} | ||
|
||
$dm = $container->get($dmServiceName); | ||
$helperSet = $application->getHelperSet(); | ||
$helperSet->set(new DocumentManagerHelper($dm), 'dm'); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php
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,44 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Output\Output; | ||
use Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\DropCommand; | ||
|
||
/** | ||
* Command to create the database schema for a set of classes based on their mappings. | ||
* | ||
* @author Justin Hileman <justin@shopopensky.com> | ||
*/ | ||
class DropSchemaDoctrineODMCommand extends DropCommand | ||
{ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setName('doctrine:odm:schema:drop') | ||
->addOption('dm', null, InputOption::PARAMETER_OPTIONAL, 'The document manager to use for this command.') | ||
->setHelp(<<<EOT | ||
The <info>doctrine:odm:schema:drop</info> command drops the default document manager's schema: | ||
<info>./symfony doctrine:odm:schema:drop</info> | ||
You can also optionally specify the name of a document manager to drop the schema for: | ||
<info>./symfony doctrine:odm:schema:drop --dm=default</info> | ||
EOT | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
DoctrineODMCommand::setApplicationDocumentManager($this->application, $input->getOption('dm')); | ||
|
||
parent::execute($input, $output); | ||
} | ||
} |