PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Helper / SymfonyQuestionHelper.php

SymfonyQuestionHelper.php in Depicter — Popup & Slider Builder 1.2.0, at vendor/symfony/console/Helper/SymfonyQuestionHelper.php

97 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Console\Helper;
13
14 use Symfony\Component\Console\Formatter\OutputFormatter;
15 use Symfony\Component\Console\Output\OutputInterface;
16 use Symfony\Component\Console\Question\ChoiceQuestion;
17 use Symfony\Component\Console\Question\ConfirmationQuestion;
18 use Symfony\Component\Console\Question\Question;
19 use Symfony\Component\Console\Style\SymfonyStyle;
20
21 /**
22 * Symfony Style Guide compliant question helper.
23 *
24 * @author Kevin Bond <kevinbond@gmail.com>
25 */
26 class SymfonyQuestionHelper extends QuestionHelper
27 {
28 /**
29 * {@inheritdoc}
30 */
31 protected function writePrompt(OutputInterface $output, Question $question)
32 {
33 $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
34 $default = $question->getDefault();
35
36 switch (true) {
37 case null === $default:
38 $text = sprintf(' <info>%s</info>:', $text);
39
40 break;
41
42 case $question instanceof ConfirmationQuestion:
43 $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
44
45 break;
46
47 case $question instanceof ChoiceQuestion && $question->isMultiselect():
48 $choices = $question->getChoices();
49 $default = explode(',', $default);
50
51 foreach ($default as $key => $value) {
52 $default[$key] = $choices[trim($value)];
53 }
54
55 $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default)));
56
57 break;
58
59 case $question instanceof ChoiceQuestion:
60 $choices = $question->getChoices();
61 $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default));
62
63 break;
64
65 default:
66 $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
67 }
68
69 $output->writeln($text);
70
71 $prompt = ' > ';
72
73 if ($question instanceof ChoiceQuestion) {
74 $output->writeln($this->formatChoiceQuestionChoices($question, 'comment'));
75
76 $prompt = $question->getPrompt();
77 }
78
79 $output->write($prompt);
80 }
81
82 /**
83 * {@inheritdoc}
84 */
85 protected function writeError(OutputInterface $output, \Exception $error)
86 {
87 if ($output instanceof SymfonyStyle) {
88 $output->newLine();
89 $output->error($error->getMessage());
90
91 return;
92 }
93
94 parent::writeError($output, $error);
95 }
96 }
97