1 | <?php |
||
21 | class ChoiceQuestion extends Question |
||
22 | { |
||
23 | private $choices; |
||
24 | private $multiselect = false; |
||
25 | private $prompt = ' > '; |
||
26 | private $errorMessage = 'Value "%s" is invalid'; |
||
27 | |||
28 | /** |
||
29 | * Constructor. |
||
30 | * |
||
31 | * @param string $question The question to ask to the user |
||
32 | * @param array $choices The list of available choices |
||
33 | * @param mixed $default The default answer to return |
||
34 | */ |
||
35 | public function __construct($question, array $choices, $default = null) |
||
43 | |||
44 | /** |
||
45 | * Returns available choices. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function getChoices() |
||
53 | |||
54 | /** |
||
55 | * Sets multiselect option. |
||
56 | * |
||
57 | * When multiselect is set to true, multiple choices can be answered. |
||
58 | * |
||
59 | * @param bool $multiselect |
||
60 | * |
||
61 | * @return ChoiceQuestion The current instance |
||
62 | */ |
||
63 | public function setMultiselect($multiselect) |
||
70 | |||
71 | /** |
||
72 | * Gets the prompt for choices. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getPrompt() |
||
80 | |||
81 | /** |
||
82 | * Sets the prompt for choices. |
||
83 | * |
||
84 | * @param string $prompt |
||
85 | * |
||
86 | * @return ChoiceQuestion The current instance |
||
87 | */ |
||
88 | public function setPrompt($prompt) |
||
94 | |||
95 | /** |
||
96 | * Sets the error message for invalid values. |
||
97 | * |
||
98 | * The error message has a string placeholder (%s) for the invalid value. |
||
99 | * |
||
100 | * @param string $errorMessage |
||
101 | * |
||
102 | * @return ChoiceQuestion The current instance |
||
103 | */ |
||
104 | public function setErrorMessage($errorMessage) |
||
111 | |||
112 | /** |
||
113 | * Returns the default answer validator. |
||
114 | * |
||
115 | * @return callable |
||
116 | */ |
||
117 | private function getDefaultValidator() |
||
177 | } |
||
178 |