From 580f7ae28ac848b6b8d22c43c5aa993a15476c7d Mon Sep 17 00:00:00 2001 From: William DURAND Date: Mon, 18 Apr 2011 21:40:16 +0200 Subject: [PATCH] Refactored command outputs --- Command/MigrationGenerateDiffCommand.php | 15 ++------------- Command/MigrationMigrateCommand.php | 9 +-------- Command/PhingCommand.php | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Command/MigrationGenerateDiffCommand.php b/Command/MigrationGenerateDiffCommand.php index 5410b8b..11ca3c6 100644 --- a/Command/MigrationGenerateDiffCommand.php +++ b/Command/MigrationGenerateDiffCommand.php @@ -45,20 +45,9 @@ EOT * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) - { + { $this->callPhing('diff'); - foreach (explode("\n", $this->buffer) as $line) { - if (false !== strpos($line, '[propel-sql-diff]')) { - $arr = preg_split('#\[propel-sql-diff\] #', $line); - $info = $arr[1]; - - if ('"' === $info[0]) { - $info = sprintf('%s', $info); - } - - $output->writeln($info); - } - } + $this->summary($output, 'propel-sql-diff'); } } diff --git a/Command/MigrationMigrateCommand.php b/Command/MigrationMigrateCommand.php index 1a80e32..e1b0e4f 100644 --- a/Command/MigrationMigrateCommand.php +++ b/Command/MigrationMigrateCommand.php @@ -68,13 +68,6 @@ EOT $this->callPhing('migrate'); } - foreach (explode("\n", $this->buffer) as $line) { - if (false !== strpos($line, '[propel-migration]')) { - $arr = preg_split('#\[propel-migration\] #', $line); - $info = $arr[1]; - - $output->writeln($info); - } - } + $this->summary($output, 'propel-migration'); } } diff --git a/Command/PhingCommand.php b/Command/PhingCommand.php index 1bc08fc..9a706b0 100644 --- a/Command/PhingCommand.php +++ b/Command/PhingCommand.php @@ -248,4 +248,24 @@ EOT; protected function getTmpDir() { return $this->tmpDir; } + + /** + * Write Propel output as summary. + * + * @param $taskname A task name + */ + protected function summary($output, $taskname) { + foreach (explode("\n", $this->buffer) as $line) { + if (false !== strpos($line, '[' . $taskname . ']')) { + $arr = preg_split('#\[' . $taskname . '\] #', $line); + $info = $arr[1]; + + if ('"' === $info[0]) { + $info = sprintf('%s', $info); + } + + $output->writeln($info); + } + } + } }