TYPO3  7.6
Question.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Question;
13 
19 class Question
20 {
21  private $question;
22  private $attempts;
23  private $hidden = false;
24  private $hiddenFallback = true;
26  private $validator;
27  private $default;
28  private $normalizer;
29 
36  public function __construct($question, $default = null)
37  {
38  $this->question = $question;
39  $this->default = $default;
40  }
41 
47  public function getQuestion()
48  {
49  return $this->question;
50  }
51 
57  public function getDefault()
58  {
59  return $this->default;
60  }
61 
67  public function isHidden()
68  {
69  return $this->hidden;
70  }
71 
81  public function setHidden($hidden)
82  {
83  if ($this->autocompleterValues) {
84  throw new \LogicException('A hidden question cannot use the autocompleter.');
85  }
86 
87  $this->hidden = (bool) $hidden;
88 
89  return $this;
90  }
91 
97  public function isHiddenFallback()
98  {
99  return $this->hiddenFallback;
100  }
101 
109  public function setHiddenFallback($fallback)
110  {
111  $this->hiddenFallback = (bool) $fallback;
112 
113  return $this;
114  }
115 
121  public function getAutocompleterValues()
122  {
124  }
125 
136  public function setAutocompleterValues($values)
137  {
138  if (is_array($values) && $this->isAssoc($values)) {
139  $values = array_merge(array_keys($values), array_values($values));
140  }
141 
142  if (null !== $values && !is_array($values)) {
143  if (!$values instanceof \Traversable || $values instanceof \Countable) {
144  throw new \InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
145  }
146  }
147 
148  if ($this->hidden) {
149  throw new \LogicException('A hidden question cannot use the autocompleter.');
150  }
151 
152  $this->autocompleterValues = $values;
153 
154  return $this;
155  }
156 
164  public function setValidator($validator)
165  {
166  $this->validator = $validator;
167 
168  return $this;
169  }
170 
176  public function getValidator()
177  {
178  return $this->validator;
179  }
180 
192  public function setMaxAttempts($attempts)
193  {
194  if (null !== $attempts && $attempts < 1) {
195  throw new \InvalidArgumentException('Maximum number of attempts must be a positive value.');
196  }
197 
198  $this->attempts = $attempts;
199 
200  return $this;
201  }
202 
210  public function getMaxAttempts()
211  {
212  return $this->attempts;
213  }
214 
224  public function setNormalizer($normalizer)
225  {
226  $this->normalizer = $normalizer;
227 
228  return $this;
229  }
230 
238  public function getNormalizer()
239  {
240  return $this->normalizer;
241  }
242 
243  protected function isAssoc($array)
244  {
245  return (bool) count(array_filter(array_keys($array), 'is_string'));
246  }
247 }