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

ArrayInput.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 5.78 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   * ArrayInput represents an input provided as an array.
016   *
017   * Usage:
018   *
019   *     $input = new ArrayInput(array('name' => 'foo', '--bar' => 'foobar'));
020   *
021   * @author Fabien Potencier <fabien@symfony.com>
022   *
023   * @api
024   */
025  class ArrayInput extends Input
026  {
027      private $parameters;
028   
029      /**
030       * Constructor.
031       *
032       * @param array           $parameters An array of parameters
033       * @param InputDefinition $definition A InputDefinition instance
034       *
035       * @api
036       */
037      public function __construct(array $parameters, InputDefinition $definition = null)
038      {
039          $this->parameters = $parameters;
040   
041          parent::__construct($definition);
042      }
043   
044      /**
045       * Returns the first argument from the raw parameters (not parsed).
046       *
047       * @return string The value of the first argument or null otherwise
048       */
049      public function getFirstArgument()
050      {
051          foreach ($this->parameters as $key => $value) {
052              if ($key && '-' === $key[0]) {
053                  continue;
054              }
055   
056              return $value;
057          }
058      }
059   
060      /**
061       * Returns true if the raw parameters (not parsed) contain a value.
062       *
063       * This method is to be used to introspect the input parameters
064       * before they have been validated. It must be used carefully.
065       *
066       * @param string|array $values The values to look for in the raw parameters (can be an array)
067       *
068       * @return bool    true if the value is contained in the raw parameters
069       */
070      public function hasParameterOption($values)
071      {
072          $values = (array) $values;
073   
074          foreach ($this->parameters as $k => $v) {
075              if (!is_int($k)) {
076                  $v = $k;
077              }
078   
079              if (in_array($v, $values)) {
080                  return true;
081              }
082          }
083   
084          return false;
085      }
086   
087      /**
088       * Returns the value of a raw option (not parsed).
089       *
090       * This method is to be used to introspect the input parameters
091       * before they have been validated. It must be used carefully.
092       *
093       * @param string|array $values  The value(s) to look for in the raw parameters (can be an array)
094       * @param mixed        $default The default value to return if no result is found
095       *
096       * @return mixed The option value
097       */
098      public function getParameterOption($values, $default = false)
099      {
100          $values = (array) $values;
101   
102          foreach ($this->parameters as $k => $v) {
103              if (is_int($k) && in_array($v, $values)) {
104                  return true;
105              } elseif (in_array($k, $values)) {
106                  return $v;
107              }
108          }
109   
110          return $default;
111      }
112   
113      /**
114       * Returns a stringified representation of the args passed to the command
115       *
116       * @return string
117       */
118      public function __toString()
119      {
120          $params = array();
121          foreach ($this->parameters as $param => $val) {
122              if ($param && '-' === $param[0]) {
123                  $params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
124              } else {
125                  $params[] = $this->escapeToken($val);
126              }
127          }
128   
129          return implode(' ', $params);
130      }
131   
132      /**
133       * Processes command line arguments.
134       */
135      protected function parse()
136      {
137          foreach ($this->parameters as $key => $value) {
138              if (0 === strpos($key, '--')) {
139                  $this->addLongOption(substr($key, 2), $value);
140              } elseif ('-' === $key[0]) {
141                  $this->addShortOption(substr($key, 1), $value);
142              } else {
143                  $this->addArgument($key, $value);
144              }
145          }
146      }
147   
148      /**
149       * Adds a short option value.
150       *
151       * @param string $shortcut The short option key
152       * @param mixed  $value    The value for the option
153       *
154       * @throws \InvalidArgumentException When option given doesn't exist
155       */
156      private function addShortOption($shortcut, $value)
157      {
158          if (!$this->definition->hasShortcut($shortcut)) {
159              throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
160          }
161   
162          $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
163      }
164   
165      /**
166       * Adds a long option value.
167       *
168       * @param string $name  The long option key
169       * @param mixed  $value The value for the option
170       *
171       * @throws \InvalidArgumentException When option given doesn't exist
172       * @throws \InvalidArgumentException When a required value is missing
173       */
174      private function addLongOption($name, $value)
175      {
176          if (!$this->definition->hasOption($name)) {
177              throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
178          }
179   
180          $option = $this->definition->getOption($name);
181   
182          if (null === $value) {
183              if ($option->isValueRequired()) {
184                  throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
185              }
186   
187              $value = $option->isValueOptional() ? $option->getDefault() : true;
188          }
189   
190          $this->options[$name] = $value;
191      }
192   
193      /**
194       * Adds an argument value.
195       *
196       * @param string $name  The argument name
197       * @param mixed  $value The value for the argument
198       *
199       * @throws \InvalidArgumentException When argument given doesn't exist
200       */
201      private function addArgument($name, $value)
202      {
203          if (!$this->definition->hasArgument($name)) {
204              throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
205          }
206   
207          $this->arguments[$name] = $value;
208      }
209  }
210