From fbd439ff01147d5e70804ec278fa59a49b2be166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Gomez?= Date: Thu, 31 Oct 2013 20:39:12 +0000 Subject: [PATCH] Reorganised a bit the commands --- Command/AbstractCommand.php | 30 ++++++++++++++++++++++++++++++ Command/MigrationDownCommand.php | 20 ++++++++++++-------- Command/MigrationStatusCommand.php | 20 ++++++++++++-------- Command/MigrationUpCommand.php | 20 ++++++++++++-------- Command/SqlInsertCommand.php | 17 ++++++++++------- 5 files changed, 76 insertions(+), 31 deletions(-) diff --git a/Command/AbstractCommand.php b/Command/AbstractCommand.php index 7dd10d8..74238ff 100644 --- a/Command/AbstractCommand.php +++ b/Command/AbstractCommand.php @@ -41,6 +41,29 @@ abstract class AbstractCommand extends ContainerAwareCommand ; } + /** + * @return \Symfony\Component\Console\Command\Command + */ + protected abstract function createSubCommandInstance(); + + /** + * @return array + */ + protected abstract function getSubCommandArguments(InputInterface $input); + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->setupBuildTimeFiles(); + + $params = $this->getSubCommandArguments($input); + $command = $this->createSubCommandInstance(); + + return $this->runCommand($command, $params, $input, $output); + } + protected function runCommand(Command $command, array $parameters, InputInterface $input, OutputInterface $output) { array_unshift($parameters, $this->getName()); @@ -77,6 +100,13 @@ abstract class AbstractCommand extends ContainerAwareCommand $this->createBuildPropertiesFile($kernel, $this->cacheDir.'/build.properties'); } + /** + * Translates a list of connection names to their DSN equivalents. + * + * @param array $connections The names. + * + * @return array + */ protected function getConnections(array $connections) { $knownConnections = $this->getContainer()->getParameter('propel.configuration'); diff --git a/Command/MigrationDownCommand.php b/Command/MigrationDownCommand.php index d05f54e..f2aa8fb 100644 --- a/Command/MigrationDownCommand.php +++ b/Command/MigrationDownCommand.php @@ -14,7 +14,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Propel\Generator\Command\MigrationDownCommand as BaseCommand; +use Propel\Generator\Command\MigrationDownCommand as BaseMigrationCommand; /** * @author Kévin Gomez @@ -33,7 +33,7 @@ class MigrationDownCommand extends AbstractCommand ->setDescription('Execute migrations down') ->addOption('connection', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Connection to use. Example: default, bookstore') - ->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseCommand::DEFAULT_MIGRATION_TABLE) + ->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseMigrationCommand::DEFAULT_MIGRATION_TABLE) ->addOption('output-dir', null, InputOption::VALUE_OPTIONAL, 'The output directory') ; } @@ -41,18 +41,22 @@ class MigrationDownCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function createSubCommandInstance() + { + return new BaseMigrationCommand(); + } + + /** + * {@inheritdoc} + */ + protected function getSubCommandArguments(InputInterface $input) { $defaultOutputDir = $this->getApplication()->getKernel()->getRootDir().'/propel/migrations'; - $this->setupBuildTimeFiles(); - - $params = array( + return array( '--connection' => $this->getConnections($input->getOption('connection')), '--migration-table' => $input->getOption('migration-table'), '--output-dir' => $input->getOption('output-dir') ?: $defaultOutputDir, ); - - return $this->runCommand(new BaseCommand(), $params, $input, $output); } } diff --git a/Command/MigrationStatusCommand.php b/Command/MigrationStatusCommand.php index 4563e5e..1f455c3 100644 --- a/Command/MigrationStatusCommand.php +++ b/Command/MigrationStatusCommand.php @@ -14,7 +14,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Propel\Generator\Command\MigrationStatusCommand as BaseCommand; +use Propel\Generator\Command\MigrationStatusCommand as BaseMigrationCommand; /** * @author Kévin Gomez @@ -33,7 +33,7 @@ class MigrationStatusCommand extends AbstractCommand ->setDescription('Get migration status') ->addOption('connection', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Connection to use. Example: default, bookstore') - ->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseCommand::DEFAULT_MIGRATION_TABLE) + ->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseMigrationCommand::DEFAULT_MIGRATION_TABLE) ->addOption('output-dir', null, InputOption::VALUE_OPTIONAL, 'The output directory') ; } @@ -41,18 +41,22 @@ class MigrationStatusCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function createSubCommandInstance() + { + return new \Propel\Generator\Command\MigrationStatusCommand(); + } + + /** + * {@inheritdoc} + */ + protected function getSubCommandArguments(InputInterface $input) { $defaultOutputDir = $this->getApplication()->getKernel()->getRootDir().'/propel/migrations'; - $this->setupBuildTimeFiles(); - - $params = array( + return array( '--connection' => $this->getConnections($input->getOption('connection')), '--migration-table' => $input->getOption('migration-table'), '--output-dir' => $input->getOption('output-dir') ?: $defaultOutputDir, ); - - return $this->runCommand(new BaseCommand(), $params, $input, $output); } } diff --git a/Command/MigrationUpCommand.php b/Command/MigrationUpCommand.php index 67732c6..c05bbb6 100644 --- a/Command/MigrationUpCommand.php +++ b/Command/MigrationUpCommand.php @@ -14,7 +14,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Propel\Generator\Command\MigrationUpCommand as BaseCommand; +use Propel\Generator\Command\MigrationUpCommand as BaseMigrationCommand; /** * @author Kévin Gomez @@ -33,7 +33,7 @@ class MigrationUpCommand extends AbstractCommand ->setDescription('Execute migrations up') ->addOption('connection', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Connection to use. Example: default, bookstore') - ->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseCommand::DEFAULT_MIGRATION_TABLE) + ->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseMigrationCommand::DEFAULT_MIGRATION_TABLE) ->addOption('output-dir', null, InputOption::VALUE_OPTIONAL, 'The output directory') ; } @@ -41,18 +41,22 @@ class MigrationUpCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function createSubCommandInstance() + { + return new \Propel\Generator\Command\MigrationUpCommand(); + } + + /** + * {@inheritdoc} + */ + protected function getSubCommandArguments(InputInterface $input) { $defaultOutputDir = $this->getApplication()->getKernel()->getRootDir().'/propel/migrations'; - $this->setupBuildTimeFiles(); - - $params = array( + return array( '--connection' => $this->getConnections($input->getOption('connection')), '--migration-table' => $input->getOption('migration-table'), '--output-dir' => $input->getOption('output-dir') ?: $defaultOutputDir, ); - - return $this->runCommand(new BaseCommand(), $params, $input, $output); } } diff --git a/Command/SqlInsertCommand.php b/Command/SqlInsertCommand.php index 0844dde..e56d53c 100644 --- a/Command/SqlInsertCommand.php +++ b/Command/SqlInsertCommand.php @@ -34,15 +34,18 @@ class SqlInsertCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function createSubCommandInstance() { - $this->setupBuildTimeFiles(); + return new \Propel\Generator\Command\SqlInsertCommand(); + } - $params = array( - '--connection' => $this->getConnections($input->getOption('connection')), + /** + * {@inheritdoc} + */ + protected function getSubCommandArguments(InputInterface $input) + { + return array( + '--connection' => $this->getConnections($input->getOption('connection')), ); - $command = new \Propel\Generator\Command\SqlInsertCommand(); - - return $this->runCommand($command, $params, $input, $output); } }