Skip to content

[FrameworkBundle][SecurityBundle] Use stderr for some other commands #20674

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -159,7 +160,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$outputMessage .= sprintf(' and domain "%s"', $domain);
}

$io->warning($outputMessage);
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
$errorIo->warning($outputMessage);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Translation\Catalogue\TargetOperation;
use Symfony\Component\Translation\Catalogue\MergeOperation;
Expand Down Expand Up @@ -85,10 +86,11 @@ public function isEnabled()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;

// 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 +99,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 +129,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 +146,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 +167,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 +201,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 +213,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 +234,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