Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Console;
4
 
5
use Illuminate\Console\View\Components\TwoColumnDetail;
6
use Symfony\Component\Console\Formatter\OutputFormatter;
7
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Question\ChoiceQuestion;
10
use Symfony\Component\Console\Question\ConfirmationQuestion;
11
use Symfony\Component\Console\Question\Question;
12
 
13
class QuestionHelper extends SymfonyQuestionHelper
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected function writePrompt(OutputInterface $output, Question $question)
19
    {
20
        $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
21
 
22
        $text = $this->ensureEndsWithPunctuation($text);
23
 
24
        $text = "  <fg=default;options=bold>$text</></>";
25
 
26
        $default = $question->getDefault();
27
 
28
        if ($question->isMultiline()) {
29
            $text .= sprintf(' (press %s to continue)', 'Windows' == PHP_OS_FAMILY
30
                ? '<comment>Ctrl+Z</comment> then <comment>Enter</comment>'
31
                : '<comment>Ctrl+D</comment>');
32
        }
33
 
34
        switch (true) {
35
            case null === $default:
36
                $text = sprintf('<info>%s</info>', $text);
37
 
38
                break;
39
 
40
            case $question instanceof ConfirmationQuestion:
41
                $text = sprintf('<info>%s (yes/no)</info> [<comment>%s</comment>]', $text, $default ? 'yes' : 'no');
42
 
43
                break;
44
 
45
            case $question instanceof ChoiceQuestion:
46
                $choices = $question->getChoices();
47
                $text = sprintf('<info>%s</info> [<comment>%s</comment>]', $text, OutputFormatter::escape($choices[$default] ?? $default));
48
 
49
                break;
50
        }
51
 
52
        $output->writeln($text);
53
 
54
        if ($question instanceof ChoiceQuestion) {
55
            foreach ($question->getChoices() as $key => $value) {
56
                with(new TwoColumnDetail($output))->render($value, $key);
57
            }
58
        }
59
 
60
        $output->write('<options=bold>❯ </>');
61
    }
62
 
63
    /**
64
     * Ensures the given string ends with punctuation.
65
     *
66
     * @param  string  $string
67
     * @return string
68
     */
69
    protected function ensureEndsWithPunctuation($string)
70
    {
71
        if (! str($string)->endsWith(['?', ':', '!', '.'])) {
72
            return "$string:";
73
        }
74
 
75
        return $string;
76
    }
77
}