Reorganised a bit the commands

This commit is contained in:
Kévin Gomez 2013-10-31 20:39:12 +00:00
parent bca3140e98
commit fbd439ff01
5 changed files with 76 additions and 31 deletions

View file

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

View file

@ -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 <contact@kevingomez.fr>
@ -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);
}
}

View file

@ -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 <contact@kevingomez.fr>
@ -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);
}
}

View file

@ -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 <contact@kevingomez.fr>
@ -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);
}
}

View file

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