Skip to content

[FrameworkBundle] Make use of stderr for non reliable output #20632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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');
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted everywhere

Copy link
Member Author

@chalasr chalasr Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh The framework now has a conflict for symfony/console: <3.3 so it should be fine


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;
}
Expand Down Expand Up @@ -98,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$config = $this->getConfigForPath($config, $path, $extensionAlias);
} catch (LogicException $e) {
$io->error($e->getMessage());
$errorIo->error($e->getMessage());

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function configure()
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>
Expand All @@ -73,10 +73,11 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();

if (null === $name = $input->getArgument('name')) {
$this->listBundles($io);
$io->comment(array(
$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)',
));
Expand All @@ -94,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$path = $input->getArgument('path');

if ($path !== null && 'yaml' !== $format) {
$io->error('The "path" option is only available for the "yaml" format.');
$errorIo->error('The "path" option is only available for the "yaml" format.');

return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();

$this->validateInput($input);
$object = $this->getContainerBuilder();

Expand All @@ -111,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} 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'));
Expand All @@ -122,15 +124,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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>)');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$options = array();
if ($event = $input->getArgument('event')) {
if (!$dispatcher->hasListeners($event)) {
$io->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
$io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$outputMessage .= sprintf(' and domain "%s"', $domain);
}

$io->warning($outputMessage);
$io->getErrorStyle()->warning($outputMessage);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ public function isEnabled()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();

// check presence of force or dump-message
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
$io->error('You must choose one of --force or --dump-messages');
$errorIo->error('You must choose one of --force or --dump-messages');

return 1;
}
Expand All @@ -97,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$writer = $this->getContainer()->get('translation.writer');
$supportedFormats = $writer->getFormats();
if (!in_array($input->getOption('output-format'), $supportedFormats)) {
$io->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.'));
$errorIo->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.'));

return 1;
}
Expand Down Expand Up @@ -127,12 +128,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$io->title('Translation Messages Extractor and Dumper');
$io->comment(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
$errorIo->title('Translation Messages Extractor and Dumper');
$errorIo->comment(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));

// load any messages from templates
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$io->comment('Parsing templates...');
$errorIo->comment('Parsing templates...');
$extractor = $this->getContainer()->get('translation.extractor');
$extractor->setPrefix($input->getOption('no-prefix') ? '' : $input->getOption('prefix'));
foreach ($transPaths as $path) {
Expand All @@ -144,7 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// load any existing messages from the translation files
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
$io->comment('Loading translation files...');
$errorIo->comment('Loading translation files...');
$loader = $this->getContainer()->get('translation.loader');
foreach ($transPaths as $path) {
$path .= 'translations';
Expand All @@ -165,7 +166,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// Exit if no messages found.
if (!count($operation->getDomains())) {
$io->warning('No translation messages were found.');
$errorIo->warning('No translation messages were found.');

return;
}
Expand Down Expand Up @@ -199,7 +200,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if ($input->getOption('output-format') == 'xlf') {
$io->comment('Xliff output version is <info>1.2</info>');
$errorIo->comment('Xliff output version is <info>1.2</info>');
}

$resultMessage = sprintf('%d message%s successfully extracted', $extractedMessagesCount, $extractedMessagesCount > 1 ? 's were' : ' was');
Expand All @@ -211,7 +212,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// save the files
if ($input->getOption('force') === true) {
$io->comment('Writing files...');
$errorIo->comment('Writing files...');

$bundleTransPath = false;
foreach ($transPaths as $path) {
Expand All @@ -232,7 +233,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$io->success($resultMessage.'.');
$errorIo->success($resultMessage.'.');
}

private function filterCatalogue(MessageCatalogue $catalogue, $domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand Down Expand Up @@ -85,8 +86,9 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;

$input->isInteractive() ? $io->title('Symfony Password Encoder Utility') : $io->newLine();
$input->isInteractive() ? $errorIo->title('Symfony Password Encoder Utility') : $errorIo->newLine();

$password = $input->getArgument('password');
$userClass = $input->getArgument('user-class');
Expand All @@ -101,22 +103,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (!$password) {
if (!$input->isInteractive()) {
$io->error('The password must not be empty.');
$errorIo->error('The password must not be empty.');

return 1;
}
$passwordQuestion = $this->createPasswordQuestion();
$password = $io->askQuestion($passwordQuestion);
$password = $errorIo->askQuestion($passwordQuestion);
}

$salt = null;

if ($input->isInteractive() && !$emptySalt) {
$emptySalt = true;

$io->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');
$errorIo->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. '.PHP_EOL.'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');

if ($io->confirm('Confirm salt generation ?')) {
if ($errorIo->confirm('Confirm salt generation ?')) {
$salt = $this->generateSalt();
$emptySalt = false;
}
Expand All @@ -136,12 +138,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io->table(array('Key', 'Value'), $rows);

if (!$emptySalt) {
$io->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
$errorIo->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
} elseif ($bcryptWithoutEmptySalt) {
$io->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
$errorIo->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
}

$io->success('Password encoding succeeded');
$errorIo->success('Password encoding succeeded');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function configure()
*/
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ protected function configure()
*/
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(
Expand All @@ -88,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
));

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;

/**
Expand Down Expand Up @@ -44,7 +45,7 @@ protected function configure()
*/
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'))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;

Expand Down Expand Up @@ -53,7 +54,7 @@ protected function configure()
*/
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();
Expand Down