Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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: 09.10.2024, 12:58 - Dateigröße: 6.01 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  /**
 015   * Input is the base class for all concrete Input classes.
 016   *
 017   * Three concrete classes are provided by default:
 018   *
 019   *  * `ArgvInput`: The input comes from the CLI arguments (argv)
 020   *  * `StringInput`: The input is provided as a string
 021   *  * `ArrayInput`: The input is provided as an array
 022   *
 023   * @author Fabien Potencier <fabien@symfony.com>
 024   */
 025  abstract class Input implements InputInterface
 026  {
 027      protected $definition;
 028      protected $options;
 029      protected $arguments;
 030      protected $interactive = true;
 031   
 032      /**
 033       * Constructor.
 034       *
 035       * @param InputDefinition $definition A InputDefinition instance
 036       */
 037      public function __construct(InputDefinition $definition = null)
 038      {
 039          if (null === $definition) {
 040              $this->arguments = array();
 041              $this->options = array();
 042              $this->definition = new InputDefinition();
 043          } else {
 044              $this->bind($definition);
 045              $this->validate();
 046          }
 047      }
 048   
 049      /**
 050       * Binds the current Input instance with the given arguments and options.
 051       *
 052       * @param InputDefinition $definition A InputDefinition instance
 053       */
 054      public function bind(InputDefinition $definition)
 055      {
 056          $this->arguments = array();
 057          $this->options = array();
 058          $this->definition = $definition;
 059   
 060          $this->parse();
 061      }
 062   
 063      /**
 064       * Processes command line arguments.
 065       */
 066      abstract protected function parse();
 067   
 068      /**
 069       * Validates the input.
 070       *
 071       * @throws \RuntimeException When not enough arguments are given
 072       */
 073      public function validate()
 074      {
 075          if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
 076              throw new \RuntimeException('Not enough arguments.');
 077          }
 078      }
 079   
 080      /**
 081       * Checks if the input is interactive.
 082       *
 083       * @return bool    Returns true if the input is interactive
 084       */
 085      public function isInteractive()
 086      {
 087          return $this->interactive;
 088      }
 089   
 090      /**
 091       * Sets the input interactivity.
 092       *
 093       * @param bool    $interactive If the input should be interactive
 094       */
 095      public function setInteractive($interactive)
 096      {
 097          $this->interactive = (bool) $interactive;
 098      }
 099   
 100      /**
 101       * Returns the argument values.
 102       *
 103       * @return array An array of argument values
 104       */
 105      public function getArguments()
 106      {
 107          return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
 108      }
 109   
 110      /**
 111       * Returns the argument value for a given argument name.
 112       *
 113       * @param string $name The argument name
 114       *
 115       * @return mixed The argument value
 116       *
 117       * @throws \InvalidArgumentException When argument given doesn't exist
 118       */
 119      public function getArgument($name)
 120      {
 121          if (!$this->definition->hasArgument($name)) {
 122              throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
 123          }
 124   
 125          return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
 126      }
 127   
 128      /**
 129       * Sets an argument value by name.
 130       *
 131       * @param string $name  The argument name
 132       * @param string $value The argument value
 133       *
 134       * @throws \InvalidArgumentException When argument given doesn't exist
 135       */
 136      public function setArgument($name, $value)
 137      {
 138          if (!$this->definition->hasArgument($name)) {
 139              throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
 140          }
 141   
 142          $this->arguments[$name] = $value;
 143      }
 144   
 145      /**
 146       * Returns true if an InputArgument object exists by name or position.
 147       *
 148       * @param string|int     $name The InputArgument name or position
 149       *
 150       * @return bool    true if the InputArgument object exists, false otherwise
 151       */
 152      public function hasArgument($name)
 153      {
 154          return $this->definition->hasArgument($name);
 155      }
 156   
 157      /**
 158       * Returns the options values.
 159       *
 160       * @return array An array of option values
 161       */
 162      public function getOptions()
 163      {
 164          return array_merge($this->definition->getOptionDefaults(), $this->options);
 165      }
 166   
 167      /**
 168       * Returns the option value for a given option name.
 169       *
 170       * @param string $name The option name
 171       *
 172       * @return mixed The option value
 173       *
 174       * @throws \InvalidArgumentException When option given doesn't exist
 175       */
 176      public function getOption($name)
 177      {
 178          if (!$this->definition->hasOption($name)) {
 179              throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
 180          }
 181   
 182          return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
 183      }
 184   
 185      /**
 186       * Sets an option value by name.
 187       *
 188       * @param string         $name  The option name
 189       * @param string|bool    $value The option value
 190       *
 191       * @throws \InvalidArgumentException When option given doesn't exist
 192       */
 193      public function setOption($name, $value)
 194      {
 195          if (!$this->definition->hasOption($name)) {
 196              throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
 197          }
 198   
 199          $this->options[$name] = $value;
 200      }
 201   
 202      /**
 203       * Returns true if an InputOption object exists by name.
 204       *
 205       * @param string $name The InputOption name
 206       *
 207       * @return bool    true if the InputOption object exists, false otherwise
 208       */
 209      public function hasOption($name)
 210      {
 211          return $this->definition->hasOption($name);
 212      }
 213   
 214      /**
 215       * Escapes a token through escapeshellarg if it contains unsafe chars
 216       *
 217       * @param string $token
 218       *
 219       * @return string
 220       */
 221      public function escapeToken($token)
 222      {
 223          return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
 224      }
 225  }
 226