Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9840193

Browse files
committed
bug #15795 [Console] Default to stderr for the console helpers (2.7+) (alcohol)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Default to stderr for the console helpers (2.7+) Interactive input/output and informational output such as progress should go to `stderr` if available. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Only merge if #15794 is merged. If someone explicitly wants to use `stdout`, they can simply pass `$output->getStream()` instead of `$output` in most use-cases. Commits ------- 90c2a96 Default to stderr for console helpers (only merge if #15794 gets merged)
2 parents d9d5dbf + 90c2a96 commit 9840193

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/Symfony/Component/Console/Helper/ProcessHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516
use Symfony\Component\Process\Exception\ProcessFailedException;
1617
use Symfony\Component\Process\Process;
@@ -37,6 +38,10 @@ class ProcessHelper extends Helper
3738
*/
3839
public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
3940
{
41+
if ($output instanceof ConsoleOutputInterface) {
42+
$output = $output->getErrorOutput();
43+
}
44+
4045
$formatter = $this->getHelperSet()->get('debug_formatter');
4146

4247
if (is_array($cmd)) {
@@ -109,6 +114,10 @@ public function mustRun(OutputInterface $output, $cmd, $error = null, $callback
109114
*/
110115
public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
111116
{
117+
if ($output instanceof ConsoleOutputInterface) {
118+
$output = $output->getErrorOutput();
119+
}
120+
112121
$formatter = $this->getHelperSet()->get('debug_formatter');
113122

114123
$that = $this;

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
/**
@@ -54,6 +55,10 @@ class ProgressBar
5455
*/
5556
public function __construct(OutputInterface $output, $max = 0)
5657
{
58+
if ($output instanceof ConsoleOutputInterface) {
59+
$output = $output->getErrorOutput();
60+
}
61+
5762
$this->output = $output;
5863
$this->setMaxSteps($max);
5964

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Console\Helper;
1313

1414
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1718
use Symfony\Component\Console\Question\Question;
@@ -41,6 +42,10 @@ class QuestionHelper extends Helper
4142
*/
4243
public function ask(InputInterface $input, OutputInterface $output, Question $question)
4344
{
45+
if ($output instanceof ConsoleOutputInterface) {
46+
$output = $output->getErrorOutput();
47+
}
48+
4449
if (!$input->isInteractive()) {
4550
return $question->getDefault();
4651
}

0 commit comments

Comments
 (0)