Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Question.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 5.47 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Console\Question;
013   
014  use Symfony\Component\Console\Exception\InvalidArgumentException;
015  use Symfony\Component\Console\Exception\LogicException;
016   
017  /**
018   * Represents a Question.
019   *
020   * @author Fabien Potencier <fabien@symfony.com>
021   */
022  class Question
023  {
024      private $question;
025      private $attempts;
026      private $hidden = false;
027      private $hiddenFallback = true;
028      private $autocompleterValues;
029      private $validator;
030      private $default;
031      private $normalizer;
032   
033      /**
034       * @param string $question The question to ask to the user
035       * @param mixed  $default  The default answer to return if the user enters nothing
036       */
037      public function __construct($question, $default = null)
038      {
039          $this->question = $question;
040          $this->default = $default;
041      }
042   
043      /**
044       * Returns the question.
045       *
046       * @return string
047       */
048      public function getQuestion()
049      {
050          return $this->question;
051      }
052   
053      /**
054       * Returns the default answer.
055       *
056       * @return mixed
057       */
058      public function getDefault()
059      {
060          return $this->default;
061      }
062   
063      /**
064       * Returns whether the user response must be hidden.
065       *
066       * @return bool
067       */
068      public function isHidden()
069      {
070          return $this->hidden;
071      }
072   
073      /**
074       * Sets whether the user response must be hidden or not.
075       *
076       * @param bool $hidden
077       *
078       * @return $this
079       *
080       * @throws LogicException In case the autocompleter is also used
081       */
082      public function setHidden($hidden)
083      {
084          if ($this->autocompleterValues) {
085              throw new LogicException('A hidden question cannot use the autocompleter.');
086          }
087   
088          $this->hidden = (bool) $hidden;
089   
090          return $this;
091      }
092   
093      /**
094       * In case the response can not be hidden, whether to fallback on non-hidden question or not.
095       *
096       * @return bool
097       */
098      public function isHiddenFallback()
099      {
100          return $this->hiddenFallback;
101      }
102   
103      /**
104       * Sets whether to fallback on non-hidden question if the response can not be hidden.
105       *
106       * @param bool $fallback
107       *
108       * @return $this
109       */
110      public function setHiddenFallback($fallback)
111      {
112          $this->hiddenFallback = (bool) $fallback;
113   
114          return $this;
115      }
116   
117      /**
118       * Gets values for the autocompleter.
119       *
120       * @return iterable|null
121       */
122      public function getAutocompleterValues()
123      {
124          return $this->autocompleterValues;
125      }
126   
127      /**
128       * Sets values for the autocompleter.
129       *
130       * @param iterable|null $values
131       *
132       * @return $this
133       *
134       * @throws InvalidArgumentException
135       * @throws LogicException
136       */
137      public function setAutocompleterValues($values)
138      {
139          if (\is_array($values)) {
140              $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
141          }
142   
143          if (null !== $values && !\is_array($values) && !$values instanceof \Traversable) {
144              throw new InvalidArgumentException('Autocompleter values can be either an array, `null` or a `Traversable` object.');
145          }
146   
147          if ($this->hidden) {
148              throw new LogicException('A hidden question cannot use the autocompleter.');
149          }
150   
151          $this->autocompleterValues = $values;
152   
153          return $this;
154      }
155   
156      /**
157       * Sets a validator for the question.
158       *
159       * @return $this
160       */
161      public function setValidator(callable $validator = null)
162      {
163          $this->validator = $validator;
164   
165          return $this;
166      }
167   
168      /**
169       * Gets the validator for the question.
170       *
171       * @return callable|null
172       */
173      public function getValidator()
174      {
175          return $this->validator;
176      }
177   
178      /**
179       * Sets the maximum number of attempts.
180       *
181       * Null means an unlimited number of attempts.
182       *
183       * @param int|null $attempts
184       *
185       * @return $this
186       *
187       * @throws InvalidArgumentException in case the number of attempts is invalid
188       */
189      public function setMaxAttempts($attempts)
190      {
191          if (null !== $attempts) {
192              $attempts = (int) $attempts;
193              if ($attempts < 1) {
194                  throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
195              }
196          }
197   
198          $this->attempts = $attempts;
199   
200          return $this;
201      }
202   
203      /**
204       * Gets the maximum number of attempts.
205       *
206       * Null means an unlimited number of attempts.
207       *
208       * @return int|null
209       */
210      public function getMaxAttempts()
211      {
212          return $this->attempts;
213      }
214   
215      /**
216       * Sets a normalizer for the response.
217       *
218       * The normalizer can be a callable (a string), a closure or a class implementing __invoke.
219       *
220       * @return $this
221       */
222      public function setNormalizer(callable $normalizer)
223      {
224          $this->normalizer = $normalizer;
225   
226          return $this;
227      }
228   
229      /**
230       * Gets the normalizer for the response.
231       *
232       * The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
233       *
234       * @return callable|null
235       */
236      public function getNormalizer()
237      {
238          return $this->normalizer;
239      }
240   
241      protected function isAssoc($array)
242      {
243          return (bool) \count(array_filter(array_keys($array), 'is_string'));
244      }
245  }
246