1 | <?php |
||
22 | class Question |
||
23 | { |
||
24 | private $question; |
||
25 | private $attempts; |
||
26 | private $hidden = false; |
||
27 | private $hiddenFallback = true; |
||
28 | private $autocompleterValues; |
||
29 | private $validator; |
||
30 | private $default; |
||
31 | private $normalizer; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param string $question The question to ask to the user |
||
37 | * @param mixed $default The default answer to return if the user enters nothing |
||
38 | */ |
||
39 | public function __construct($question, $default = null) |
||
44 | |||
45 | /** |
||
46 | * Returns the question. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getQuestion() |
||
54 | |||
55 | /** |
||
56 | * Returns the default answer. |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function getDefault() |
||
64 | |||
65 | /** |
||
66 | * Returns whether the user response must be hidden. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function isHidden() |
||
74 | |||
75 | /** |
||
76 | * Sets whether the user response must be hidden or not. |
||
77 | * |
||
78 | * @param bool $hidden |
||
79 | * |
||
80 | * @return Question The current instance |
||
81 | * |
||
82 | * @throws LogicException In case the autocompleter is also used |
||
83 | */ |
||
84 | public function setHidden($hidden) |
||
94 | |||
95 | /** |
||
96 | * In case the response can not be hidden, whether to fallback on non-hidden question or not. |
||
97 | * |
||
98 | * @return bool |
||
99 | */ |
||
100 | public function isHiddenFallback() |
||
104 | |||
105 | /** |
||
106 | * Sets whether to fallback on non-hidden question if the response can not be hidden. |
||
107 | * |
||
108 | * @param bool $fallback |
||
109 | * |
||
110 | * @return Question The current instance |
||
111 | */ |
||
112 | public function setHiddenFallback($fallback) |
||
118 | |||
119 | /** |
||
120 | * Gets values for the autocompleter. |
||
121 | * |
||
122 | * @return null|array|\Traversable |
||
123 | */ |
||
124 | public function getAutocompleterValues() |
||
128 | |||
129 | /** |
||
130 | * Sets values for the autocompleter. |
||
131 | * |
||
132 | * @param null|array|\Traversable $values |
||
133 | * |
||
134 | * @return Question The current instance |
||
135 | * |
||
136 | * @throws InvalidArgumentException |
||
137 | * @throws LogicException |
||
138 | */ |
||
139 | public function setAutocompleterValues($values) |
||
159 | |||
160 | /** |
||
161 | * Sets a validator for the question. |
||
162 | * |
||
163 | * @param null|callable $validator |
||
164 | * |
||
165 | * @return Question The current instance |
||
166 | */ |
||
167 | public function setValidator($validator) |
||
173 | |||
174 | /** |
||
175 | * Gets the validator for the question. |
||
176 | * |
||
177 | * @return null|callable |
||
178 | */ |
||
179 | public function getValidator() |
||
183 | |||
184 | /** |
||
185 | * Sets the maximum number of attempts. |
||
186 | * |
||
187 | * Null means an unlimited number of attempts. |
||
188 | * |
||
189 | * @param null|int $attempts |
||
190 | * |
||
191 | * @return Question The current instance |
||
192 | * |
||
193 | * @throws InvalidArgumentException In case the number of attempts is invalid. |
||
194 | */ |
||
195 | public function setMaxAttempts($attempts) |
||
205 | |||
206 | /** |
||
207 | * Gets the maximum number of attempts. |
||
208 | * |
||
209 | * Null means an unlimited number of attempts. |
||
210 | * |
||
211 | * @return null|int |
||
212 | */ |
||
213 | public function getMaxAttempts() |
||
217 | |||
218 | /** |
||
219 | * Sets a normalizer for the response. |
||
220 | * |
||
221 | * The normalizer can be a callable (a string), a closure or a class implementing __invoke. |
||
222 | * |
||
223 | * @param callable $normalizer |
||
224 | * |
||
225 | * @return Question The current instance |
||
226 | */ |
||
227 | public function setNormalizer($normalizer) |
||
233 | |||
234 | /** |
||
235 | * Gets the normalizer for the response. |
||
236 | * |
||
237 | * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. |
||
238 | * |
||
239 | * @return callable |
||
240 | */ |
||
241 | public function getNormalizer() |
||
245 | |||
246 | protected function isAssoc($array) |
||
250 | } |
||
251 |