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

Skip to content

Commit f4cfc0a

Browse files
committed
[FrameworkBundle] Make use of stderr for non reliable output
1 parent e4c95ed commit f4cfc0a

10 files changed

+32
-23
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: 4 additions & 2 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
/**
@@ -70,8 +71,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
7071
$io = new SymfonyStyle($input, $output);
7172

7273
if (null === $name = $input->getArgument('name')) {
73-
$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>)');
74+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
75+
$this->listBundles($errorIo);
76+
$errorIo->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>)');
7577

7678
return;
7779
}

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;
@@ -93,6 +94,8 @@ protected function configure()
9394
protected function execute(InputInterface $input, OutputInterface $output)
9495
{
9596
$io = new SymfonyStyle($input, $output);
97+
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
98+
9699
$this->validateInput($input);
97100
$object = $this->getContainerBuilder();
98101

@@ -110,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
110113
} elseif ($tag = $input->getOption('tag')) {
111114
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
112115
} elseif ($name = $input->getArgument('name')) {
113-
$name = $this->findProperServiceName($input, $io, $object, $name);
116+
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
114117
$options = array('id' => $name);
115118
} else {
116119
$options = array('show_private' => $input->getOption('show-private'));
@@ -120,15 +123,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
120123
$options['format'] = $input->getOption('format');
121124
$options['raw_text'] = $input->getOption('raw');
122125
$options['output'] = $io;
123-
$helper->describe($output, $object, $options);
126+
$helper->describe($io, $object, $options);
124127

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

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\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
@@ -68,7 +68,7 @@ protected function configure()
6868
*/
6969
protected function execute(InputInterface $input, OutputInterface $output)
7070
{
71-
$io = new SymfonyStyle($input, $output);
71+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
7272

7373
if (null === $documentRoot = $input->getOption('docroot')) {
7474
$documentRoot = $this->getContainer()->getParameter('kernel.root_dir').'/../web';

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
/**
@@ -68,7 +69,7 @@ protected function configure()
6869
*/
6970
protected function execute(InputInterface $input, OutputInterface $output)
7071
{
71-
$io = new SymfonyStyle($input, $cliOutput = $output);
72+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
7273

7374
if (!extension_loaded('pcntl')) {
7475
$io->error(array(
@@ -77,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7778
));
7879

7980
if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) {
80-
return $this->getApplication()->find('server:run')->run($input, $cliOutput);
81+
return $this->getApplication()->find('server:run')->run($input, $output);
8182
}
8283

8384
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)