10000 [FrameworkBundle] Make use of stderr for non reliable output · symfony/symfony@3aebb3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 3aebb3a

Browse files
committed
[FrameworkBundle] Make use of stderr for non reliable output
1 parent 546ec68 commit 3aebb3a

11 files changed

+76
-18
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ protected function configure()
5959
protected function execute(InputInterface $input, OutputInterface $output)
6060
{
6161
$io = new SymfonyStyle($input, $output);
62+
$errorIo = $io->getErrorIo();
63+
6264
if (false !== strpos($input->getFirstArgument(), ':d')) {
63-
$io->caution('The use of "config:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:config" instead.');
65+
$errorIo->caution('The use of "config:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:config" instead.');
6466
}
6567

6668
$name = $input->getArgument('name');
6769

6870
if (empty($name)) {
69-
$io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration.');
70-
$io->newLine();
71-
$this->listBundles($output);
71+
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration.');
72+
$errorIo->newLine();
73+
$this->listBundles($errorIo);
7274

7375
return;
7476
}

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ protected function configure()
6868
protected function execute(InputInterface $input, OutputInterface $output)
6969
{
7070
$io = new SymfonyStyle($input, $output);
71+
$errorIo = $io->getErrorIo();
7172
$name = $input->getArgument('name');
7273

7374
if (empty($name)) {
74-
$io->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration.');
75-
$io->newLine();
76-
$this->listBundles($output);
75+
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration.');
76+
$errorIo->newLine();
77+
$this->listBundles($errorIo);
7778

7879
return;
7980
}

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ protected function configure()
9595
protected function execute(InputInterface $input, OutputInterface $output)
9696
{
9797
$io = new SymfonyStyle($input, $output);
98+
$errorIo = $io->getErrorIo();
99+
98100
if (false !== strpos($input->getFirstArgument(), ':d')) {
99-
$io->caution('The use of "container:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:container" instead.');
101+
$errorIo->caution('The use of "container:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:container" instead.');
100102
}
101103

102104
$this->validateInput($input);
@@ -112,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
112114
} elseif ($tag = $input->getOption('tag')) {
113115
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
114116
} elseif ($name = $input->getArgument('name')) {
115-
$name = $this->findProperServiceName($input, $io, $object, $name);
117+
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
116118
$options = array('id' => $name);
117119
} else {
118120
$options = array('show_private' => $input->getOption('show-private'));
@@ -122,10 +124,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
122124
$options['format'] = $input->getOption('format');
123125
$options['raw_text'] = $input->getOption('raw');
124126
$options['output'] = $io;
125-
$helper->describe($output, $object, $options);
127+
$helper->describe($io, $object, $options);
126128

127129
if (!$input->getArgument('name') && $input->isInteractive()) {
128-
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
130+
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
129131
}
130132
}
131133

src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6565
$options = array();
6666
if ($event = $input->getArgument('event')) {
6767
if (!$dispatcher->hasListeners($event)) {
68-
$io->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
68+
$io->getErrorIo()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
6969

70< F438 code>70
return;
7171
}

src/Symfony/Bundle/FrameworkBundle/Command/RouterApacheDumperCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ protected function configure()
7676
protected function execute(InputInterface $input, OutputInterface $output)
7777
{
7878
$io = new SymfonyStyle($input, $output);
79+
$errorIo = $io->getErrorIo();
7980

80-
$io->title('Router Apache Dumper');
81-
$io->caution('The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0.');
81+
$errorIo->title('Router Apache Dumper');
82+
$errorIo->caution('The router:dump-apache command is deprecated since version 2.5 and will be removed in 3.0.');
8283

8384
$router = $this->getContainer()->get('router');
8485

src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8181
$io = new SymfonyStyle($input, $output);
8282

8383
if (false !== strpos($input->getFirstArgument(), ':d')) {
84-
$io->caution('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.');
84+
$io->getErrorIo()->caution('The use of "router:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:router" instead.');
8585
}
8686

8787
$name = $input->getArgument('name');

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696
{
9797
$io = new SymfonyStyle($input, $output);
9898
if (false !== strpos($input->getFirstArgument(), ':d')) {
99-
$io->caution('The use of "translation:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:translation" instead.');
99+
$io->getErrorIo()->caution('The use of "translation:debug" command is deprecated since version 2.7 and will be removed in 3.0. Use the "debug:translation" instead.');
100100
}
101101

102102
$locale = $input->getArgument('locale');
@@ -153,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
153153
$outputMessage .= sprintf(' and domain "%s"', $domain);
154154
}
155155

156-
$io->warning($outputMessage);
156+
$io->getErrorIo()->warning($outputMessage);
157157

158158
return;
159159
}

src/Symfony/Bundle/FrameworkBundle/Command/YamlLintCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ protected function configure()
6464
protected function execute(InputInterface $input, OutputInterface $output)
6565
{
6666
$io = new SymfonyStyle($input, $output);
67+
6768
if (false !== strpos($input->getFirstArgument(), ':l')) {
68-
$io->caution('The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.');
69+
$io->getErrorIo()->caution('The use of "yaml:lint" command is deprecated since version 2.7 and will be removed in 3.0. Use the "lint:yaml" instead.');
6970
}
7071

7172
$filename = $input->getArgument('filename');

src/Symfony/Component/Console/Style/OutputStyle.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
1515
use Symfony\Component\Console\Helper\ProgressBar;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1718

1819
/**
1920
* Decorates output to add console style guide helpers.
@@ -113,4 +114,13 @@ public function getFormatter()
113114
{
114115
return $this->output->getFormatter();
115116
}
117+
118+
protected function getErrorOutput()
119+
{
120+
if (!$this->output instanceof ConsoleOutputInterface) {
121+
return;
122+
}
123+
124+
return $this->output->getErrorOutput();
125+
}
116126
}

src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,21 @@ public function newLine($count = 1)
336336
$this->bufferedOutput->write(str_repeat("\n", $count));
337337
}
338338

339+
/**
340+
* Returns a new instance which makes use of stderr if available, the current instance
341+
* otherwise.
342+
*
343+
* @return self
344+
*/
345+
public function getErrorIo()
346+
{
347+
if (!$stderr = $this->getErrorOutput()) {
348+
return $this;
349+
}
350+
351+
return new self($this->input, $stderr);
352+
}
353+
339354
/**
340355
* @return ProgressBar
341356
*/

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Style\SymfonyStyle;
1919
use Symfony\Component\Console\Tester\CommandTester;
20+
use Symfony\Component\Console\Formatter\OutputFormatter;
2021

2122
class SymfonyStyleTest extends PHPUnit_Framework_TestCase
2223
{
@@ -54,6 +55,31 @@ public function inputCommandToOutputFilesProvider()
5455

5556
return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
5657
}
58+
59+
public function testGetErrorIo()
60+
{
61+
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
62+
63+
$errorOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
64+
$errorOutput
65+
->method('getFormatter')
66+
->willReturn(new OutputFormatter());
67+
$errorOutput
68+
->expects($this->once())
69+
->method('write');
70+
71+
$output = $this->getMock('Symfony\Component\Console\Output\ConsoleOutputInterface');
72+
$output
73+
->method('getFormatter')
74+
->willReturn(new OutputFormatter());
75+
$output
76+
->expects($this->once())
77+
->method('getErrorOutput')
78+
->willReturn($errorOutput);
79+
80+
$io = new SymfonyStyle($input, $output);
81+
$io->getErrorIo()->write('');
82+
}
5783
}
5884

5985
/**

0 commit comments

Comments
 (0)
0