Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dadbebe

Browse filesBrowse files
committed
[FrameworkBundle] Make use of stderr for non reliable output
1 parent a4edafb commit dadbebe
Copy full SHA for dadbebe

9 files changed

+164
-16
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ protected function configure()
5858
protected function execute(InputInterface $input, OutputInterface $output)
5959
{
6060
$io = new SymfonyStyle($input, $output);
61+
$errorIo = $io->getErrorIo();
6162

6263
if (null === $name = $input->getArgument('name')) {
63-
$this->listBundles($io);
64-
$io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
65-
$io->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
66-
67-
return;
64+
$this->listBundles($errorIo);
65+
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
66+
$errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
6867
}
6968

7069
$extension = $this->findExtension($name);
@@ -94,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9493
try {
9594
$config = $this->getConfigForPath($config, $path, $extensionAlias);
9695
} catch (LogicException $e) {
97-
$io->error($e->getMessage());
96+
$errorIo->error($e->getMessage());
9897

9998
return;
10099
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171

7272
if (null === $name = $input->getArgument('name')) {
7373
$this->listBundles($io);
74-
$io->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g. <comment>config:dump-reference FrameworkBundle</comment>)');
75-
76-
return;
74+
$io->getErrorIo()->comment('Provide the name of a bundle as the first argument of this command to dump its default configuration. (e.g. <comment>config:dump-reference FrameworkBundle</comment>)');
7775
}
7876

7977
$extension = $this->findExtension($name);

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ protected function configure()
9292
protected function execute(InputInterface $input, OutputInterface $output)
9393
{
9494
$io = new SymfonyStyle($input, $output);
95+
$errorIo = $io->getErrorIo();
96+
9597
$this->validateInput($input);
9698
$object = $this->getContainerBuilder();
9799

@@ -105,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
105107
} elseif ($tag = $input->getOption('tag')) {
106108
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
107109
} elseif ($name = $input->getArgument('name')) {
108-
$name = $this->findProperServiceName($input, $io, $object, $name);
110+
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
109111
$options = array('id' => $name);
110112
} else {
111113
$options = array('show_private' => $input->getOption('show-private'));
@@ -115,15 +117,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
115117
$options['format'] = $input->getOption('format');
116118
$options['raw_text'] = $input->getOption('raw');
117119
$options['output'] = $io;
118-
$helper->describe($output, $object, $options);
120+
$helper->describe($io, $object, $options);
119121

120122
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
121123
if ($input->getOption('tags')) {
122-
$io->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
124+
$errorIo->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
123125
} elseif ($input->getOption('parameters')) {
124-
$io->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
126+
$errorIo->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
125127
} else {
126-
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
128+
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
127129
}
128130
}
129131
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php
+1-1Lines 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

7070
return;
7171
}
+98Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Command;
13+
14+
use Symfony\Component\Console\Input\InputArgument;
15+
use Symfony\Component\Console\Input\InputOption;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Style\SymfonyStyle;
19+
use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
20+
use Symfony\Component\Routing\RouterInterface;
21+
22+
/**
23+
* RouterApacheDumperCommand.
24+
*
25+
* @deprecated since version 2.5, to be removed in 3.0.
26+
* The performance gains are minimal and it's very hard to replicate
27+
* the behavior of PHP implementation.
28+
*
29+
* @author Fabien Potencier <fabien@symfony.com>
30+
*/
31+
class RouterApacheDumperCommand extends ContainerAwareCommand
32+
{
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function isEnabled()
37+
{
38+
if (!$this->getContainer()->has('router')) {
39+
return false;
40+
}
41+
$router = $this->getContainer()->get('router');
42+
if (!$router instanceof RouterInterface) {
43+
return false;
44+
}
45+
46+
return parent::isEnabled();
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
protected function configure()
53+
{
54+
$this
55+
->setName('router:dump-apache')
56+
->setDefinition(array(
57+
new InputArgument('script_name', InputArgument::OPTIONAL, 'The script name of the application\'s front controller'),
58+
new InputOption('base-uri', null, InputOption::VALUE_REQUIRED, 'The base URI'),
59+
))
60+
->setDescription('[DEPRECATED] Dumps all routes as Apache rewrite rules')
61+
->setHelp(<<<'EOF'
62+
The <info>%command.name%</info> dumps all routes as Apache rewrite rules.
63+
These can then be used with the ApacheUrlMatcher to use Apache for route
64+
matching.
65+
66+
<info>php %command.full_name%</info>
67+
68+
EOF
69+
)
70+
;
71+
}
72+
73+
/**
74+
* {@inheritdoc}
75+
*/
76+
protected function execute(InputInterface $input, OutputInterface $output)
77+
{
78+
$io = new SymfonyStyle($input, $output);
79+
$errorIo = $io->getErrorIo();
80+
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.');
83+
84+
$router = $this->getContainer()->get('router');
85+
86+
$dumpOptions = array();
87+
if ($input->getArgument('script_name')) {
88+
$dumpOptions['script_name'] = $input->getArgument('script_name');
89+
}
90+
if ($input->getOption('base-uri')) {
91+
$dumpOptions['base_uri'] = $input->getOption('base-uri');
92+
}
93+
94+
$dumper = new ApacheMatcherDumper($router->getRouteCollection());
95+
96+
$io->writeln($dumper->dump($dumpOptions), OutputInterface::OUTPUT_RAW);
97+
}
98+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
159159
$outputMessage .= sprintf(' and domain "%s"', $domain);
160160
}
161161

162-
$io->warning($outputMessage);
162+
$io->getErrorIo()->warning($outputMessage);
163163

164164
return;
165165
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Style/OutputStyle.php
+10Lines 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.
@@ -145,4 +146,13 @@ public function isDebug()
145146
{
146147
return $this->output->isDebug();
147148
}
149+
150+
protected function getErrorOutput()
151+
{
152+
if (!$this->output instanceof ConsoleOutputInterface) {
153+
return;
154+
}
155+
156+
return $this->output->getErrorOutput();
157+
}
148158
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Style/SymfonyStyle.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,21 @@ public function newLine($count = 1)
337337
$this->bufferedOutput->write(str_repeat("\n", $count));
338338
}
339339

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\Console\Style\SymfonyStyle;
1717
use Symfony\Component\Console\Tester\CommandTester;
18+
use Symfony\Component\Console\Formatter\OutputFormatter;
1819

1920
class SymfonyStyleTest extends PHPUnit_Framework_TestCase
2021
{
@@ -71,4 +72,29 @@ public function inputCommandToOutputFilesProvider()
7172

7273
return array_map(null, glob($baseDir.'/command/command_*.php'), glob($baseDir.'/output/output_*.txt'));
7374
}
75+
76+
public function testGetErrorIo()
77+
{
78+
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
79+
80+
$errorOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
81+
$errorOutput
82+
->method('getFormatter')
83+
->willReturn(new OutputFormatter());
84+
$errorOutput
85+
->expects($this->once())
86+
->method('write');
87+
88+
$output = $this->getMock('Symfony\Component\Console\Output\ConsoleOutputInterface');
89+
$output
90+
->method('getFormatter')
91+
->willReturn(new OutputFormatter());
92+
$output
93+
->expects($this->once())
94+
->method('getErrorOutput')
95+
->willReturn($errorOutput);
96+
97+
$io = new SymfonyStyle($input, $output);
98+
$io->getErrorIo()->write('');
99+
}
74100
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.