1 | <?php |
||
29 | class Question |
||
30 | { |
||
31 | private $question; |
||
32 | private $attempts; |
||
33 | private $hidden = false; |
||
34 | private $hiddenFallback = true; |
||
35 | private $autocompleterValues; |
||
36 | private $validator; |
||
37 | private $default; |
||
38 | private $normalizer; |
||
39 | |||
40 | /** |
||
41 | * Constructor. |
||
42 | * |
||
43 | * @param string $question The question to ask to the user |
||
44 | * @param mixed $default The default answer to return if the user enters nothing |
||
45 | */ |
||
46 | public function __construct($question, $default = null) |
||
51 | |||
52 | /** |
||
53 | * Returns the question. |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getQuestion() |
||
61 | |||
62 | /** |
||
63 | * Returns the default answer. |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function getDefault() |
||
71 | |||
72 | /** |
||
73 | * Returns whether the user response must be hidden. |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function isHidden() |
||
81 | |||
82 | /** |
||
83 | * Sets whether the user response must be hidden or not. |
||
84 | * |
||
85 | * @param bool $hidden |
||
86 | * |
||
87 | * @return Question The current instance |
||
88 | * |
||
89 | * @throws LogicException In case the autocompleter is also used |
||
90 | */ |
||
91 | public function setHidden($hidden) |
||
101 | |||
102 | /** |
||
103 | * In case the response can not be hidden, whether to fallback on non-hidden question or not. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function isHiddenFallback() |
||
111 | |||
112 | /** |
||
113 | * Sets whether to fallback on non-hidden question if the response can not be hidden. |
||
114 | * |
||
115 | * @param bool $fallback |
||
116 | * |
||
117 | * @return Question The current instance |
||
118 | */ |
||
119 | public function setHiddenFallback($fallback) |
||
125 | |||
126 | /** |
||
127 | * Gets values for the autocompleter. |
||
128 | * |
||
129 | * @return null|array|\Traversable |
||
130 | */ |
||
131 | public function getAutocompleterValues() |
||
135 | |||
136 | /** |
||
137 | * Sets values for the autocompleter. |
||
138 | * |
||
139 | * @param null|array|\Traversable $values |
||
140 | * |
||
141 | * @return Question The current instance |
||
142 | * |
||
143 | * @throws InvalidArgumentException |
||
144 | * @throws LogicException |
||
145 | */ |
||
146 | public function setAutocompleterValues($values) |
||
166 | |||
167 | /** |
||
168 | * Sets a validator for the question. |
||
169 | * |
||
170 | * @param null|callable $validator |
||
171 | * |
||
172 | * @return Question The current instance |
||
173 | */ |
||
174 | public function setValidator($validator) |
||
180 | |||
181 | /** |
||
182 | * Gets the validator for the question. |
||
183 | * |
||
184 | * @return null|callable |
||
185 | */ |
||
186 | public function getValidator() |
||
190 | |||
191 | /** |
||
192 | * Sets the maximum number of attempts. |
||
193 | * |
||
194 | * Null means an unlimited number of attempts. |
||
195 | * |
||
196 | * @param null|int $attempts |
||
197 | * |
||
198 | * @return Question The current instance |
||
199 | * |
||
200 | * @throws InvalidArgumentException In case the number of attempts is invalid. |
||
201 | */ |
||
202 | public function setMaxAttempts($attempts) |
||
212 | |||
213 | /** |
||
214 | * Gets the maximum number of attempts. |
||
215 | * |
||
216 | * Null means an unlimited number of attempts. |
||
217 | * |
||
218 | * @return null|int |
||
219 | */ |
||
220 | public function getMaxAttempts() |
||
224 | |||
225 | /** |
||
226 | * Sets a normalizer for the response. |
||
227 | * |
||
228 | * The normalizer can be a callable (a string), a closure or a class implementing __invoke. |
||
229 | * |
||
230 | * @param callable $normalizer |
||
231 | * |
||
232 | * @return Question The current instance |
||
233 | */ |
||
234 | public function setNormalizer($normalizer) |
||
240 | |||
241 | /** |
||
242 | * Gets the normalizer for the response. |
||
243 | * |
||
244 | * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. |
||
245 | * |
||
246 | * @return callable |
||
247 | */ |
||
248 | public function getNormalizer() |
||
252 | |||
253 | protected function isAssoc($array) |
||
257 | } |
||
258 |