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