Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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: 09.10.2024, 12:56 - Dateigröße: 5.75 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       * Constructor.
 035       *
 036       * @param string $question The question to ask to the user
 037       * @param mixed  $default  The default answer to return if the user enters nothing
 038       */
 039      public function __construct($question, $default = null)
 040      {
 041          $this->question = $question;
 042          $this->default = $default;
 043      }
 044   
 045      /**
 046       * Returns the question.
 047       *
 048       * @return string
 049       */
 050      public function getQuestion()
 051      {
 052          return $this->question;
 053      }
 054   
 055      /**
 056       * Returns the default answer.
 057       *
 058       * @return mixed
 059       */
 060      public function getDefault()
 061      {
 062          return $this->default;
 063      }
 064   
 065      /**
 066       * Returns whether the user response must be hidden.
 067       *
 068       * @return bool
 069       */
 070      public function isHidden()
 071      {
 072          return $this->hidden;
 073      }
 074   
 075      /**
 076       * Sets whether the user response must be hidden or not.
 077       *
 078       * @param bool $hidden
 079       *
 080       * @return Question The current instance
 081       *
 082       * @throws LogicException In case the autocompleter is also used
 083       */
 084      public function setHidden($hidden)
 085      {
 086          if ($this->autocompleterValues) {
 087              throw new LogicException('A hidden question cannot use the autocompleter.');
 088          }
 089   
 090          $this->hidden = (bool) $hidden;
 091   
 092          return $this;
 093      }
 094   
 095      /**
 096       * In case the response can not be hidden, whether to fallback on non-hidden question or not.
 097       *
 098       * @return bool
 099       */
 100      public function isHiddenFallback()
 101      {
 102          return $this->hiddenFallback;
 103      }
 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)
 113      {
 114          $this->hiddenFallback = (bool) $fallback;
 115   
 116          return $this;
 117      }
 118   
 119      /**
 120       * Gets values for the autocompleter.
 121       *
 122       * @return null|array|\Traversable
 123       */
 124      public function getAutocompleterValues()
 125      {
 126          return $this->autocompleterValues;
 127      }
 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)
 140      {
 141          if (is_array($values)) {
 142              $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
 143          }
 144   
 145          if (null !== $values && !is_array($values)) {
 146              if (!$values instanceof \Traversable || !$values instanceof \Countable) {
 147                  throw new InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
 148              }
 149          }
 150   
 151          if ($this->hidden) {
 152              throw new LogicException('A hidden question cannot use the autocompleter.');
 153          }
 154   
 155          $this->autocompleterValues = $values;
 156   
 157          return $this;
 158      }
 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)
 168      {
 169          $this->validator = $validator;
 170   
 171          return $this;
 172      }
 173   
 174      /**
 175       * Gets the validator for the question.
 176       *
 177       * @return null|callable
 178       */
 179      public function getValidator()
 180      {
 181          return $this->validator;
 182      }
 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)
 196      {
 197          if (null !== $attempts && $attempts < 1) {
 198              throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
 199          }
 200   
 201          $this->attempts = $attempts;
 202   
 203          return $this;
 204      }
 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()
 214      {
 215          return $this->attempts;
 216      }
 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)
 228      {
 229          $this->normalizer = $normalizer;
 230   
 231          return $this;
 232      }
 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()
 242      {
 243          return $this->normalizer;
 244      }
 245   
 246      protected function isAssoc($array)
 247      {
 248          return (bool) count(array_filter(array_keys($array), 'is_string'));
 249      }
 250  }
 251