1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheAentMachine\Question; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
|
9
|
|
|
final class QuestionFactory |
10
|
|
|
{ |
11
|
|
|
/** @var InputInterface */ |
12
|
|
|
private $input; |
13
|
|
|
|
14
|
|
|
/** @var OutputInterface */ |
15
|
|
|
private $output; |
16
|
|
|
|
17
|
|
|
/** @var QuestionHelper */ |
18
|
|
|
private $questionHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* QuestionFactory constructor. |
22
|
|
|
* @param InputInterface $input |
23
|
|
|
* @param OutputInterface $output |
24
|
|
|
* @param QuestionHelper $questionHelper |
25
|
|
|
*/ |
26
|
|
|
public function __construct(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper) |
27
|
|
|
{ |
28
|
|
|
$this->input = $input; |
29
|
|
|
$this->output = $output; |
30
|
|
|
$this->questionHelper = $questionHelper; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function question(string $question, bool $printAnswer = true): Question |
34
|
|
|
{ |
35
|
|
|
return new Question($this->input, $this->output, $this->questionHelper, $question, $printAnswer); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $question |
40
|
|
|
* @param string[] $choices |
41
|
|
|
* @param bool $printAnswer |
42
|
|
|
* @return ChoiceQuestion |
43
|
|
|
*/ |
44
|
|
|
public function choiceQuestion(string $question, array $choices, bool $printAnswer = true): ChoiceQuestion |
45
|
|
|
{ |
46
|
|
|
return new ChoiceQuestion($this->input, $this->output, $this->questionHelper, $question, $choices, $printAnswer); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|