Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/console/Input/ArgvInput.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
95 */ | 95 */ |
96 private function parseShortOption($token) | 96 private function parseShortOption($token) |
97 { | 97 { |
98 $name = substr($token, 1); | 98 $name = substr($token, 1); |
99 | 99 |
100 if (strlen($name) > 1) { | 100 if (\strlen($name) > 1) { |
101 if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) { | 101 if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) { |
102 // an option with a value (with no space) | 102 // an option with a value (with no space) |
103 $this->addShortOption($name[0], substr($name, 1)); | 103 $this->addShortOption($name[0], substr($name, 1)); |
104 } else { | 104 } else { |
105 $this->parseShortOptionSet($name); | 105 $this->parseShortOptionSet($name); |
116 * | 116 * |
117 * @throws RuntimeException When option given doesn't exist | 117 * @throws RuntimeException When option given doesn't exist |
118 */ | 118 */ |
119 private function parseShortOptionSet($name) | 119 private function parseShortOptionSet($name) |
120 { | 120 { |
121 $len = strlen($name); | 121 $len = \strlen($name); |
122 for ($i = 0; $i < $len; ++$i) { | 122 for ($i = 0; $i < $len; ++$i) { |
123 if (!$this->definition->hasShortcut($name[$i])) { | 123 if (!$this->definition->hasShortcut($name[$i])) { |
124 throw new RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i])); | 124 $encoding = mb_detect_encoding($name, null, true); |
125 throw new RuntimeException(sprintf('The "-%s" option does not exist.', false === $encoding ? $name[$i] : mb_substr($name, $i, 1, $encoding))); | |
125 } | 126 } |
126 | 127 |
127 $option = $this->definition->getOptionForShortcut($name[$i]); | 128 $option = $this->definition->getOptionForShortcut($name[$i]); |
128 if ($option->acceptValue()) { | 129 if ($option->acceptValue()) { |
129 $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1)); | 130 $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1)); |
143 private function parseLongOption($token) | 144 private function parseLongOption($token) |
144 { | 145 { |
145 $name = substr($token, 2); | 146 $name = substr($token, 2); |
146 | 147 |
147 if (false !== $pos = strpos($name, '=')) { | 148 if (false !== $pos = strpos($name, '=')) { |
148 if (0 === strlen($value = substr($name, $pos + 1))) { | 149 if (0 === \strlen($value = substr($name, $pos + 1))) { |
149 // if no value after "=" then substr() returns "" since php7 only, false before | 150 // if no value after "=" then substr() returns "" since php7 only, false before |
150 // see http://php.net/manual/fr/migration70.incompatible.php#119151 | 151 // see http://php.net/manual/fr/migration70.incompatible.php#119151 |
151 if (\PHP_VERSION_ID < 70000 && false === $value) { | 152 if (\PHP_VERSION_ID < 70000 && false === $value) { |
152 $value = ''; | 153 $value = ''; |
153 } | 154 } |
166 * | 167 * |
167 * @throws RuntimeException When too many arguments are given | 168 * @throws RuntimeException When too many arguments are given |
168 */ | 169 */ |
169 private function parseArgument($token) | 170 private function parseArgument($token) |
170 { | 171 { |
171 $c = count($this->arguments); | 172 $c = \count($this->arguments); |
172 | 173 |
173 // if input is expecting another argument, add it | 174 // if input is expecting another argument, add it |
174 if ($this->definition->hasArgument($c)) { | 175 if ($this->definition->hasArgument($c)) { |
175 $arg = $this->definition->getArgument($c); | 176 $arg = $this->definition->getArgument($c); |
176 $this->arguments[$arg->getName()] = $arg->isArray() ? array($token) : $token; | 177 $this->arguments[$arg->getName()] = $arg->isArray() ? [$token] : $token; |
177 | 178 |
178 // if last argument isArray(), append token to last argument | 179 // if last argument isArray(), append token to last argument |
179 } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) { | 180 } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) { |
180 $arg = $this->definition->getArgument($c - 1); | 181 $arg = $this->definition->getArgument($c - 1); |
181 $this->arguments[$arg->getName()][] = $token; | 182 $this->arguments[$arg->getName()][] = $token; |
182 | 183 |
183 // unexpected argument | 184 // unexpected argument |
184 } else { | 185 } else { |
185 $all = $this->definition->getArguments(); | 186 $all = $this->definition->getArguments(); |
186 if (count($all)) { | 187 if (\count($all)) { |
187 throw new RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all)))); | 188 throw new RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all)))); |
188 } | 189 } |
189 | 190 |
190 throw new RuntimeException(sprintf('No arguments expected, got "%s".', $token)); | 191 throw new RuntimeException(sprintf('No arguments expected, got "%s".', $token)); |
191 } | 192 } |
226 | 227 |
227 if (null !== $value && !$option->acceptValue()) { | 228 if (null !== $value && !$option->acceptValue()) { |
228 throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); | 229 throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); |
229 } | 230 } |
230 | 231 |
231 if (in_array($value, array('', null), true) && $option->acceptValue() && count($this->parsed)) { | 232 if (\in_array($value, ['', null], true) && $option->acceptValue() && \count($this->parsed)) { |
232 // if option accepts an optional or mandatory argument | 233 // if option accepts an optional or mandatory argument |
233 // let's see if there is one provided | 234 // let's see if there is one provided |
234 $next = array_shift($this->parsed); | 235 $next = array_shift($this->parsed); |
235 if ((isset($next[0]) && '-' !== $next[0]) || in_array($next, array('', null), true)) { | 236 if ((isset($next[0]) && '-' !== $next[0]) || \in_array($next, ['', null], true)) { |
236 $value = $next; | 237 $value = $next; |
237 } else { | 238 } else { |
238 array_unshift($this->parsed, $next); | 239 array_unshift($this->parsed, $next); |
239 } | 240 } |
240 } | 241 } |
301 public function getParameterOption($values, $default = false, $onlyParams = false) | 302 public function getParameterOption($values, $default = false, $onlyParams = false) |
302 { | 303 { |
303 $values = (array) $values; | 304 $values = (array) $values; |
304 $tokens = $this->tokens; | 305 $tokens = $this->tokens; |
305 | 306 |
306 while (0 < count($tokens)) { | 307 while (0 < \count($tokens)) { |
307 $token = array_shift($tokens); | 308 $token = array_shift($tokens); |
308 if ($onlyParams && '--' === $token) { | 309 if ($onlyParams && '--' === $token) { |
309 return false; | 310 return $default; |
310 } | 311 } |
311 | 312 |
312 foreach ($values as $value) { | 313 foreach ($values as $value) { |
313 if ($token === $value) { | 314 if ($token === $value) { |
314 return array_shift($tokens); | 315 return array_shift($tokens); |
316 // Options with values: | 317 // Options with values: |
317 // For long options, test for '--option=' at beginning | 318 // For long options, test for '--option=' at beginning |
318 // For short options, test for '-o' at beginning | 319 // For short options, test for '-o' at beginning |
319 $leading = 0 === strpos($value, '--') ? $value.'=' : $value; | 320 $leading = 0 === strpos($value, '--') ? $value.'=' : $value; |
320 if ('' !== $leading && 0 === strpos($token, $leading)) { | 321 if ('' !== $leading && 0 === strpos($token, $leading)) { |
321 return substr($token, strlen($leading)); | 322 return substr($token, \strlen($leading)); |
322 } | 323 } |
323 } | 324 } |
324 } | 325 } |
325 | 326 |
326 return $default; | 327 return $default; |