1 | <?php |
||
28 | class ChoiceQuestion extends Question |
||
29 | { |
||
30 | private $choices; |
||
31 | private $multiselect = false; |
||
32 | private $prompt = ' > '; |
||
33 | private $errorMessage = 'Value "%s" is invalid'; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param string $question The question to ask to the user |
||
39 | * @param array $choices The list of available choices |
||
40 | * @param mixed $default The default answer to return |
||
41 | */ |
||
42 | public function __construct($question, array $choices, $default = null) |
||
50 | |||
51 | /** |
||
52 | * Returns available choices. |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | public function getChoices() |
||
60 | |||
61 | /** |
||
62 | * Sets multiselect option. |
||
63 | * |
||
64 | * When multiselect is set to true, multiple choices can be answered. |
||
65 | * |
||
66 | * @param bool $multiselect |
||
67 | * |
||
68 | * @return ChoiceQuestion The current instance |
||
69 | */ |
||
70 | public function setMultiselect($multiselect) |
||
77 | |||
78 | /** |
||
79 | * Gets the prompt for choices. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getPrompt() |
||
87 | |||
88 | /** |
||
89 | * Sets the prompt for choices. |
||
90 | * |
||
91 | * @param string $prompt |
||
92 | * |
||
93 | * @return ChoiceQuestion The current instance |
||
94 | */ |
||
95 | public function setPrompt($prompt) |
||
101 | |||
102 | /** |
||
103 | * Sets the error message for invalid values. |
||
104 | * |
||
105 | * The error message has a string placeholder (%s) for the invalid value. |
||
106 | * |
||
107 | * @param string $errorMessage |
||
108 | * |
||
109 | * @return ChoiceQuestion The current instance |
||
110 | */ |
||
111 | public function setErrorMessage($errorMessage) |
||
118 | |||
119 | /** |
||
120 | * Returns the default answer validator. |
||
121 | * |
||
122 | * @return callable |
||
123 | */ |
||
124 | private function getDefaultValidator() |
||
184 | } |
||
185 |