Add Symfony proxies for Doctrine ODM schema:create and schema:drop console commands.

This commit is contained in:
Justin Hileman 2010-09-07 16:41:59 -04:00 committed by Fabien Potencier
parent 15fa905bd4
commit 51553211f3
3 changed files with 117 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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');
}
}

View File

@ -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);
}
}