|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheAentMachine\Helper; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
|
7
|
|
|
use Symfony\Component\Console\Helper\FormatterHelper; |
|
8
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use TheAentMachine\Question\CommonQuestions; |
|
12
|
|
|
use TheAentMachine\Question\QuestionFactory; |
|
13
|
|
|
use TheAentMachine\Question\Question; |
|
14
|
|
|
use TheAentMachine\Question\ChoiceQuestion; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* A helper class for the most common questions asked in the console. |
|
18
|
|
|
*/ |
|
19
|
|
|
final class AentHelper |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var InputInterface */ |
|
22
|
|
|
private $input; |
|
23
|
|
|
|
|
24
|
|
|
/** @var OutputInterface */ |
|
25
|
|
|
private $output; |
|
26
|
|
|
|
|
27
|
|
|
/** @var QuestionHelper */ |
|
28
|
|
|
private $questionHelper; |
|
29
|
|
|
|
|
30
|
|
|
/** @var FormatterHelper */ |
|
31
|
|
|
private $formatterHelper; |
|
32
|
|
|
|
|
33
|
|
|
/** @var QuestionFactory */ |
|
34
|
|
|
private $factory; |
|
35
|
|
|
|
|
36
|
|
|
/** @var CommonQuestions */ |
|
37
|
|
|
private $commonQuestions; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
public function __construct(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper, FormatterHelper $formatterHelper) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->input = $input; |
|
43
|
|
|
$this->output = $output; |
|
44
|
|
|
$this->questionHelper = $questionHelper; |
|
45
|
|
|
$this->formatterHelper = $formatterHelper; |
|
46
|
|
|
$this->factory = new QuestionFactory($input, $output, $questionHelper); |
|
47
|
|
|
$this->commonQuestions = new CommonQuestions($input, $output, $questionHelper); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function registerStyle(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$outputStyle = new OutputFormatterStyle('black', 'cyan', ['bold']); |
|
53
|
|
|
$this->output->getFormatter()->setStyle('title', $outputStyle); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Displays text in a big block |
|
58
|
|
|
*/ |
|
59
|
|
|
public function title(string $title): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->registerStyle(); |
|
62
|
|
|
$this->spacer(); |
|
63
|
|
|
$this->output->writeln($this->formatterHelper->formatBlock($title, 'title', true)); |
|
64
|
|
|
$this->spacer(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Displays text in a small block |
|
69
|
|
|
*/ |
|
70
|
|
|
public function subTitle(string $title): void |
|
71
|
|
|
{ |
|
72
|
|
|
$this->registerStyle(); |
|
73
|
|
|
$this->output->writeln($this->formatterHelper->formatBlock($title, 'title', false)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function spacer(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->output->writeln(''); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function question(string $question, bool $printAnswer = true): Question |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->factory->question($question, $printAnswer); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $question |
|
88
|
|
|
* @param string[] $choices |
|
89
|
|
|
* @param bool $printAnswer |
|
90
|
|
|
* @return ChoiceQuestion |
|
91
|
|
|
*/ |
|
92
|
|
|
public function choiceQuestion(string $question, array $choices, bool $printAnswer = true): ChoiceQuestion |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->factory->choiceQuestion($question, $choices, $printAnswer); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return CommonQuestions |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getCommonQuestions(): CommonQuestions |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->commonQuestions; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|