[FrameworkBundle] Make use of stderr for non reliable output

This commit is contained in:
Robin Chalas 2016-11-20 14:10:42 +01:00
parent 136a5ffc55
commit 1ee48bfd60
No known key found for this signature in database
GPG Key ID: 89672113756EE03B
10 changed files with 33 additions and 24 deletions

View File

@ -87,9 +87,7 @@ EOF
$twig = $this->getTwigEnvironment();
if (null === $twig) {
$io->error('The Twig environment needs to be set.');
return 1;
throw new \RuntimeException('The Twig environment needs to be set.');
}
$types = array('functions', 'filters', 'tests', 'globals');

View File

@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;
@ -88,9 +89,7 @@ EOF
$io = new SymfonyStyle($input, $output);
if (null === $twig = $this->getTwigEnvironment()) {
$io->error('The Twig environment needs to be set.');
return 1;
throw new \RuntimeException('The Twig environment needs to be set.');
}
$filenames = $input->getArgument('filename');

View File

@ -15,6 +15,7 @@ use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Yaml\Yaml;
@ -62,11 +63,12 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
if (null === $name = $input->getArgument('name')) {
$this->listBundles($io);
$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>)');
$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)');
$this->listBundles($errorIo);
$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>)');
$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)');
return;
}
@ -98,7 +100,7 @@ EOF
try {
$config = $this->getConfigForPath($config, $path, $extensionAlias);
} catch (LogicException $e) {
$io->error($e->getMessage());
$errorIo->error($e->getMessage());
return;
}

View File

@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
@ -55,7 +56,7 @@ this is either <comment>yaml</comment> or <comment>xml</comment>.
When the option is not provided, <comment>yaml</comment> is used.
<info>php %command.full_name% FrameworkBundle --format=xml</info>
For dumping a specific option, add its path as second argument (only available for the yaml format):
<info>php %command.full_name% framework profiler.matcher</info>
@ -75,8 +76,9 @@ EOF
$io = new SymfonyStyle($input, $output);
if (null === $name = $input->getArgument('name')) {
$this->listBundles($io);
$io->comment(array(
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
$this->listBundles($errorIo);
$errorIo->comment(array(
'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>)',
'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)',
));

View File

@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -94,6 +95,8 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
$this->validateInput($input);
$object = $this->getContainerBuilder();
@ -111,7 +114,7 @@ EOF
} elseif ($tag = $input->getOption('tag')) {
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
} elseif ($name = $input->getArgument('name')) {
$name = $this->findProperServiceName($input, $io, $object, $name);
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
$options = array('id' => $name);
} else {
$options = array('show_private' => $input->getOption('show-private'));
@ -122,15 +125,15 @@ EOF
$options['show_arguments'] = $input->getOption('show-arguments');
$options['raw_text'] = $input->getOption('raw');
$options['output'] = $io;
$helper->describe($output, $object, $options);
$helper->describe($io, $object, $options);
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
if ($input->getOption('tags')) {
$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>)');
$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>)');
} elseif ($input->getOption('parameters')) {
$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>)');
$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>)');
} else {
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
}
}
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -65,7 +66,8 @@ EOF
$options = array();
if ($event = $input->getArgument('event')) {
if (!$dispatcher->hasListeners($event)) {
$io->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
$errorIo->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
return;
}

View File

@ -79,7 +79,7 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
if (null === $documentRoot = $input->getOption('docroot')) {
if (!$this->documentRoot) {

View File

@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
@ -79,7 +80,7 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $cliOutput = $output);
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
if (!extension_loaded('pcntl')) {
$io->error(array(
@ -88,7 +89,7 @@ EOF
));
if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) {
return $this->getApplication()->find('server:run')->run($input, $cliOutput);
return $this->getApplication()->find('server:run')->run($input, $output);
}
return 1;

View File

@ -15,6 +15,7 @@ use Symfony\Bundle\WebServerBundle\WebServer;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
@ -44,7 +45,7 @@ class ServerStatusCommand extends ServerCommand
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
$server = new WebServer();
if ($server->isRunning($input->getOption('pidfile'))) {
$io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile'))));

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\WebServerBundle\Command;
use Symfony\Bundle\WebServerBundle\WebServer;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Style\SymfonyStyle;
@ -53,7 +54,7 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
try {
$server = new WebServer();