From bd64c555aadec2e72047573734320ab434c735e0 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 17 May 2011 00:21:20 +0200 Subject: [PATCH] Refactored PhingCommand to check Propel database configuration before to launch a command --- Command/PhingCommand.php | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/Command/PhingCommand.php b/Command/PhingCommand.php index 38cb880..21d5f36 100644 --- a/Command/PhingCommand.php +++ b/Command/PhingCommand.php @@ -2,24 +2,12 @@ namespace Propel\PropelBundle\Command; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; +use Symfony\Bundle\FrameworkBundle\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; use Symfony\Component\HttpKernel\Util\Filesystem; use Symfony\Component\Finder\Finder; -/* - * This file is part of the Symfony framework. - * - * (c) Fabien Potencier - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - /** * Wrapper command for Phing tasks * @@ -34,6 +22,22 @@ abstract class PhingCommand extends Command protected $buffer = null; protected $buildPropertiesFile = null; + /** + * {@inheritdoc} + */ + protected function initialize(InputInterface $input, OutputInterface $output) + { + parent::initialize($input, $output); + + $this->checkConfiguration(); + } + + /** + * Call a Phing task. + * + * @param string $taskName A Propel task name. + * @param array $properties An array of properties to pass to Phing. + */ protected function callPhing($taskName, $properties = array()) { $kernel = $this->getApplication()->getKernel(); @@ -169,7 +173,7 @@ abstract class PhingCommand extends Command $container = $this->getApplication()->getKernel()->getContainer(); if (!$container->has('propel.configuration')) { - throw new \InvalidArgumentException('Could not find Propel configuration.'); + throw new \InvalidArgumentException('Could not find Propel configuration.'); } $xml = strtr(<<container->get('propel.configuration')->getParameters(); + if (0 === count($parameters['datasources'])) { + throw new \RuntimeException('Propel should be configured (no database configuration found).'); + } + } }