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