Skip to content

Commit

Permalink
Refactored commands, added a new method in PhingCommand to handle '--…
Browse files Browse the repository at this point in the history
…connection' option
  • Loading branch information
willdurand committed Apr 19, 2011
1 parent d4c541c commit f5b580e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Command/PhingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,33 @@ protected function getTmpDir() {
return $this->tmpDir;
}

/**
* Get connection by checking the input option named 'connection'.
* Returns the default connection if no option specified or an exception
* if the specified connection doesn't exist.
*
* @param InputInterface $input
* @param OutputInterface $output
* @throw \InvalidArgumentException If the connection does not exist.
* @return array A Propel Configuration as an array.
*/
protected function getConnection(InputInterface $input, OutputInterface $output) {
$container = $this->getApplication()->getKernel()->getContainer();
$propelConfiguration = $container->get('propel.configuration');
$name = $input->getOption('connection') ?: $container->getParameter('propel.dbal.default_connection');


if (isset($propelConfiguration['datasources'][$name])) {
$defaultConfig = $propelConfiguration['datasources'][$name];
} else {
throw new \InvalidArgumentException(sprintf('Connection named %s doesn\'t exist', $name));
}

$output->writeln(sprintf('<info>Use connection named <comment>%s</comment></info>', $name));

return $defaultConfig;
}

/**
* Write Propel output as summary.
*
Expand Down

0 comments on commit f5b580e

Please sign in to comment.