From a5f36a8a7c1efb365d1a77c17df926ebe3151cd9 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 17 Jun 2014 12:13:24 +0200 Subject: [PATCH 1/2] [Console] Add threshold for ProcessHelper verbosity --- .../Component/Console/Helper/ProcessHelper.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/ProcessHelper.php b/src/Symfony/Component/Console/Helper/ProcessHelper.php index 2ae780b801..1bb9d23f67 100644 --- a/src/Symfony/Component/Console/Helper/ProcessHelper.php +++ b/src/Symfony/Component/Console/Helper/ProcessHelper.php @@ -26,15 +26,16 @@ class ProcessHelper extends Helper /** * Runs an external process. * - * @param OutputInterface $output An OutputInterface instance - * @param string|array|Process $cmd An instance of Process or an array of arguments to escape and run or a command to run - * @param string|null $error An error message that must be displayed if something went wrong - * @param callable|null $callback A PHP callback to run whenever there is some - * output available on STDOUT or STDERR + * @param OutputInterface $output An OutputInterface instance + * @param string|array|Process $cmd An instance of Process or an array of arguments to escape and run or a command to run + * @param string|null $error An error message that must be displayed if something went wrong + * @param callable|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR + * @param int $verbosity The threshold for verbosity * * @return Process The process that ran */ - public function run(OutputInterface $output, $cmd, $error = null, $callback = null) + public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE) { $formatter = $this->getHelperSet()->get('debug_formatter'); @@ -46,7 +47,7 @@ class ProcessHelper extends Helper $process = new Process($cmd); } - if ($output->isVeryVerbose()) { + if ($verbosity <= $output->getVerbosity()) { $output->write($formatter->start(spl_object_hash($process), $process->getCommandLine())); } @@ -56,7 +57,7 @@ class ProcessHelper extends Helper $process->run($callback); - if ($output->isVeryVerbose()) { + if ($verbosity <= $output->getVerbosity()) { $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode()); $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful())); } From 6ca1c90eb7344d6fd84db5899bd4261f445c8c95 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 17 Jun 2014 01:47:52 +0200 Subject: [PATCH 2/2] [FrameworkBundle] Use ProcessHelper for server:run command --- .../FrameworkBundle/Command/ServerRunCommand.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php index f8faaf7658..c132453366 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php @@ -95,16 +95,13 @@ EOF $builder->setTimeout(null); $process = $builder->getProcess(); - if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { - $callback = function ($type, $buffer) use ($output) { - $output->write($buffer); - }; - } else { - $callback = null; + if (OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { $process->disableOutput(); } - - $process->run($callback); + + $this + ->getHelper('process') + ->run($output, $process, null, null, OutputInterface::VERBOSITY_VERBOSE); } private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env)