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

Skip to content

Commit 1ee48bf

Browse files
committed
[FrameworkBundle] Make use of stderr for non reliable output
1 parent 136a5ff commit 1ee48bf

10 files changed

+33
-24
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
$twig = $this->getTwigEnvironment();
8888

8989
if (null === $twig) {
90-
$io->error('The Twig environment needs to be set.');
91-
92-
return 1;
90+
throw new \RuntimeException('The Twig environment needs to be set.');
9391
}
9492

9593
$types = array('functions', 'filters', 'tests', 'globals');

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
2021
use Symfony\Component\Finder\Finder;
2122

@@ -88,9 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8889
$io = new SymfonyStyle($input, $output);
8990

9091
if (null === $twig = $this->getTwigEnvironment()) {
91-
$io->error('The Twig environment needs to be set.');
92-
93-
return 1;
92+
throw new \RuntimeException('The Twig environment needs to be set.');
9493
}
9594

9695
$filenames = $input->getArgument('filename');

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920
use Symfony\Component\Console\Exception\LogicException;
2021
use Symfony\Component\Yaml\Yaml;
@@ -62,11 +63,12 @@ protected function configure()
6263
protected function execute(InputInterface $input, OutputInterface $output)
6364
{
6465
$io = new SymfonyStyle($input, $output);
66+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
6567

6668
if (null === $name = $input->getArgument('name')) {
67-
$this->listBundles($io);
68-
$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>)');
69-
$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)');
69+
$this->listBundles($errorIo);
70+
$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>)');
71+
$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)');
7072

7173
return;
7274
}
@@ -98,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
98100
try {
99101
$config = $this->getConfigForPath($config, $path, $extensionAlias);
100102
} catch (LogicException $e) {
101-
$io->error($e->getMessage());
103+
$errorIo->error($e->getMessage());
102104

103105
return;
104106
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Input\InputInterface;
1919
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2021
use Symfony\Component\Console\Style\SymfonyStyle;
2122

2223
/**
@@ -55,7 +56,7 @@ protected function configure()
5556
When the option is not provided, <comment>yaml</comment> is used.
5657
5758
<info>php %command.full_name% FrameworkBundle --format=xml</info>
58-
59+
5960
For dumping a specific option, add its path as second argument (only available for the yaml format):
6061
6162
<info>php %command.full_name% framework profiler.matcher</info>
@@ -75,8 +76,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
7576
$io = new SymfonyStyle($input, $output);
7677

7778
if (null === $name = $input->getArgument('name')) {
78-
$this->listBundles($io);
79-
$io->comment(array(
79+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
80+
$this->listBundles($errorIo);
81+
$errorIo->comment(array(
8082
'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>)',
8183
'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
8284
));

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
2021
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2122
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -94,6 +95,8 @@ protected function configure()
9495
protected function execute(InputInterface $input, OutputInterface $output)
9596
{
9697
$io = new SymfonyStyle($input, $output);
98+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
99+
97100
$this->validateInput($input);
98101
$object = $this->getContainerBuilder();
99102

@@ -111,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
111114
} elseif ($tag = $input->getOption('tag')) {
112115
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
113116
} elseif ($name = $input->getArgument('name')) {
114-
$name = $this->findProperServiceName($input, $io, $object, $name);
117+
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
115118
$options = array('id' => $name);
116119
} else {
117120
$options = array('show_private' => $input->getOption('show-private'));
@@ -122,15 +125,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
122125
$options['show_arguments'] = $input->getOption('show-arguments');
123126
$options['raw_text'] = $input->getOption('raw');
124127
$options['output'] = $io;
125-
$helper->describe($output, $object, $options);
128+
$helper->describe($io, $object, $options);
126129

127130
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
128131
if ($input->getOption('tags')) {
129-
$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>)');
132+
$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>)');
130133
} elseif ($input->getOption('parameters')) {
131-
$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>)');
134+
$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>)');
132135
} else {
133-
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
136+
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
134137
}
135138
}
136139
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Input 10000 \InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1920
use Symfony\Component\Console\Style\SymfonyStyle;
2021
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2122

@@ -65,7 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6566
$options = array();
6667
if ($event = $input->getArgument('event')) {
6768
if (!$dispatcher->hasListeners($event)) {
68-
$io->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
69+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
70+
$errorIo->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
6971

7072
return;
7173
}

src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function configure()
7979
*/
8080
protected function execute(InputInterface $input, OutputInterface $output)
8181
{
82-
$io = new SymfonyStyle($input, $output);
82+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
8383

8484
if (null === $documentRoot = $input->getOption('docroot')) {
8585
if (!$this->documentRoot) {

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\InputOption;
1919
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2021
use Symfony\Component\Console\Style\SymfonyStyle;
2122

2223
/**
@@ -79,7 +80,7 @@ protected function configure()
798 10795 0
*/
8081
protected function execute(InputInterface $input, OutputInterface $output)
8182
{
82-
$io = new SymfonyStyle($input, $cliOutput = $output);
83+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
8384

8485
if (!extension_loaded('pcntl')) {
8586
$io->error(array(
@@ -88,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8889
));
8990

9091
if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) {
91-
return $this->getApplication()->find('server:run')->run($input, $cliOutput);
92+
return $this->getApplication()->find('server:run')->run($input, $output);
9293
}
9394

9495
return 1;

src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
/**
@@ -44,7 +45,7 @@ protected function configure()
4445
*/
4546
protected function execute(InputInterface $input, OutputInterface $output)
4647
{
47-
$io = new SymfonyStyle($input, $output);
48+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
4849
$server = new WebServer();
4950
if ($server->isRunning($input->getOption('pidfile'))) {
5051
$io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile'))));

src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\WebServerBundle\WebServer;
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920

@@ -53,7 +54,7 @@ protected function configure()
5354
*/
5455
protected function execute(InputInterface $input, OutputInterface $output)
5556
{
56-
$io = new SymfonyStyle($input, $output);
57+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
5758

5859
try {
5960
$server = new WebServer();

0 commit comments

Comments
 (0)
0