summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Helper/SymfonyQuestionHelper.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/console/Helper/SymfonyQuestionHelper.php')
-rw-r--r--vendor/symfony/console/Helper/SymfonyQuestionHelper.php31
1 files changed, 24 insertions, 7 deletions
diff --git a/vendor/symfony/console/Helper/SymfonyQuestionHelper.php b/vendor/symfony/console/Helper/SymfonyQuestionHelper.php
index 942278bd..cf071d59 100644
--- a/vendor/symfony/console/Helper/SymfonyQuestionHelper.php
+++ b/vendor/symfony/console/Helper/SymfonyQuestionHelper.php
@@ -18,6 +18,7 @@ use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
+use Symfony\Component\Console\Formatter\OutputFormatter;
/**
* Symfony Style Guide compliant question helper.
@@ -28,6 +29,8 @@ class SymfonyQuestionHelper extends QuestionHelper
{
/**
* {@inheritdoc}
+ *
+ * To be removed in 4.0
*/
public function ask(InputInterface $input, OutputInterface $output, Question $question)
{
@@ -35,11 +38,13 @@ class SymfonyQuestionHelper extends QuestionHelper
$question->setValidator(function ($value) use ($validator) {
if (null !== $validator) {
$value = $validator($value);
- }
+ } else {
+ // make required
+ if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
+ @trigger_error('The default question validator is deprecated since Symfony 3.3 and will not be used anymore in version 4.0. Set a custom question validator if needed.', E_USER_DEPRECATED);
- // make required
- if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
- throw new LogicException('A value is required.');
+ throw new LogicException('A value is required.');
+ }
}
return $value;
@@ -53,7 +58,7 @@ class SymfonyQuestionHelper extends QuestionHelper
*/
protected function writePrompt(OutputInterface $output, Question $question)
{
- $text = $question->getQuestion();
+ $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
$default = $question->getDefault();
switch (true) {
@@ -67,14 +72,26 @@ class SymfonyQuestionHelper extends QuestionHelper
break;
+ case $question instanceof ChoiceQuestion && $question->isMultiselect():
+ $choices = $question->getChoices();
+ $default = explode(',', $default);
+
+ foreach ($default as $key => $value) {
+ $default[$key] = $choices[trim($value)];
+ }
+
+ $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default)));
+
+ break;
+
case $question instanceof ChoiceQuestion:
$choices = $question->getChoices();
- $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
+ $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default]));
break;
default:
- $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $default);
+ $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
}
$output->writeln($text);