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

Input.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.86 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\Input;
013   
014  use Symfony\Component\Console\Exception\InvalidArgumentException;
015  use Symfony\Component\Console\Exception\RuntimeException;
016   
017  /**
018   * Input is the base class for all concrete Input classes.
019   *
020   * Three concrete classes are provided by default:
021   *
022   *  * `ArgvInput`: The input comes from the CLI arguments (argv)
023   *  * `StringInput`: The input is provided as a string
024   *  * `ArrayInput`: The input is provided as an array
025   *
026   * @author Fabien Potencier <fabien@symfony.com>
027   */
028  abstract class Input implements InputInterface, StreamableInputInterface
029  {
030      protected $definition;
031      protected $stream;
032      protected $options = [];
033      protected $arguments = [];
034      protected $interactive = true;
035   
036      public function __construct(InputDefinition $definition = null)
037      {
038          if (null === $definition) {
039              $this->definition = new InputDefinition();
040          } else {
041              $this->bind($definition);
042              $this->validate();
043          }
044      }
045   
046      /**
047       * {@inheritdoc}
048       */
049      public function bind(InputDefinition $definition)
050      {
051          $this->arguments = [];
052          $this->options = [];
053          $this->definition = $definition;
054   
055          $this->parse();
056      }
057   
058      /**
059       * Processes command line arguments.
060       */
061      abstract protected function parse();
062   
063      /**
064       * {@inheritdoc}
065       */
066      public function validate()
067      {
068          $definition = $this->definition;
069          $givenArguments = $this->arguments;
070   
071          $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) {
072              return !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired();
073          });
074   
075          if (\count($missingArguments) > 0) {
076              throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
077          }
078      }
079   
080      /**
081       * {@inheritdoc}
082       */
083      public function isInteractive()
084      {
085          return $this->interactive;
086      }
087   
088      /**
089       * {@inheritdoc}
090       */
091      public function setInteractive($interactive)
092      {
093          $this->interactive = (bool) $interactive;
094      }
095   
096      /**
097       * {@inheritdoc}
098       */
099      public function getArguments()
100      {
101          return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
102      }
103   
104      /**
105       * {@inheritdoc}
106       */
107      public function getArgument($name)
108      {
109          if (!$this->definition->hasArgument($name)) {
110              throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
111          }
112   
113          return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
114      }
115   
116      /**
117       * {@inheritdoc}
118       */
119      public function setArgument($name, $value)
120      {
121          if (!$this->definition->hasArgument($name)) {
122              throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
123          }
124   
125          $this->arguments[$name] = $value;
126      }
127   
128      /**
129       * {@inheritdoc}
130       */
131      public function hasArgument($name)
132      {
133          return $this->definition->hasArgument($name);
134      }
135   
136      /**
137       * {@inheritdoc}
138       */
139      public function getOptions()
140      {
141          return array_merge($this->definition->getOptionDefaults(), $this->options);
142      }
143   
144      /**
145       * {@inheritdoc}
146       */
147      public function getOption($name)
148      {
149          if (!$this->definition->hasOption($name)) {
150              throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
151          }
152   
153          return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
154      }
155   
156      /**
157       * {@inheritdoc}
158       */
159      public function setOption($name, $value)
160      {
161          if (!$this->definition->hasOption($name)) {
162              throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
163          }
164   
165          $this->options[$name] = $value;
166      }
167   
168      /**
169       * {@inheritdoc}
170       */
171      public function hasOption($name)
172      {
173          return $this->definition->hasOption($name);
174      }
175   
176      /**
177       * Escapes a token through escapeshellarg if it contains unsafe chars.
178       *
179       * @param string $token
180       *
181       * @return string
182       */
183      public function escapeToken($token)
184      {
185          return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
186      }
187   
188      /**
189       * {@inheritdoc}
190       */
191      public function setStream($stream)
192      {
193          $this->stream = $stream;
194      }
195   
196      /**
197       * {@inheritdoc}
198       */
199      public function getStream()
200      {
201          return $this->stream;
202      }
203  }
204