Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/console/Helper/QuestionHelper.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/vendor/symfony/console/Helper/QuestionHelper.php Tue Jul 10 15:07:59 2018 +0100 +++ b/vendor/symfony/console/Helper/QuestionHelper.php Thu Feb 28 13:21:36 2019 +0000 @@ -19,8 +19,8 @@ use Symfony\Component\Console\Input\StreamableInputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question; -use Symfony\Component\Console\Question\ChoiceQuestion; /** * The QuestionHelper class provides helpers to interact with the user. @@ -47,13 +47,23 @@ } if (!$input->isInteractive()) { - if ($question instanceof ChoiceQuestion) { + $default = $question->getDefault(); + + if (null !== $default && $question instanceof ChoiceQuestion) { $choices = $question->getChoices(); - return $choices[$question->getDefault()]; + if (!$question->isMultiselect()) { + return isset($choices[$default]) ? $choices[$default] : $default; + } + + $default = explode(',', $default); + foreach ($default as $k => $v) { + $v = trim($v); + $default[$k] = isset($choices[$v]) ? $choices[$v] : $v; + } } - return $question->getDefault(); + return $default; } if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) { @@ -87,7 +97,7 @@ { @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use %s::setStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED); - if (!is_resource($stream)) { + if (!\is_resource($stream)) { throw new InvalidArgumentException('Input stream must be a valid resource.'); } @@ -104,7 +114,7 @@ */ public function getInputStream() { - if (0 === func_num_args() || func_get_arg(0)) { + if (0 === \func_num_args() || func_get_arg(0)) { @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use %s::getStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED); } @@ -130,7 +140,7 @@ /** * Asks the question to the user. * - * @return bool|mixed|null|string + * @return bool|mixed|string|null * * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden */ @@ -161,10 +171,10 @@ $ret = trim($ret); } } else { - $ret = trim($this->autocomplete($output, $question, $inputStream, is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false))); + $ret = trim($this->autocomplete($output, $question, $inputStream, \is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false))); } - $ret = strlen($ret) > 0 ? $ret : $question->getDefault(); + $ret = \strlen($ret) > 0 ? $ret : $question->getDefault(); if ($normalizer = $question->getNormalizer()) { return $normalizer($ret); @@ -181,7 +191,7 @@ $message = $question->getQuestion(); if ($question instanceof ChoiceQuestion) { - $maxWidth = max(array_map(array($this, 'strlen'), array_keys($question->getChoices()))); + $maxWidth = max(array_map([$this, 'strlen'], array_keys($question->getChoices()))); $messages = (array) $question->getQuestion(); foreach ($question->getChoices() as $key => $value) { @@ -228,7 +238,7 @@ $i = 0; $ofs = -1; $matches = $autocomplete; - $numMatches = count($matches); + $numMatches = \count($matches); $sttyMode = shell_exec('stty -g'); @@ -253,7 +263,7 @@ if (0 === $i) { $ofs = -1; $matches = $autocomplete; - $numMatches = count($matches); + $numMatches = \count($matches); } else { $numMatches = 0; } @@ -277,13 +287,13 @@ $ofs += ('A' === $c[2]) ? -1 : 1; $ofs = ($numMatches + $ofs) % $numMatches; } - } elseif (ord($c) < 32) { + } elseif (\ord($c) < 32) { if ("\t" === $c || "\n" === $c) { if ($numMatches > 0 && -1 !== $ofs) { $ret = $matches[$ofs]; // Echo out remaining chars for current match $output->write(substr($ret, $i)); - $i = strlen($ret); + $i = \strlen($ret); } if ("\n" === $c) { @@ -342,7 +352,7 @@ */ private function getHiddenResponse(OutputInterface $output, $inputStream) { - if ('\\' === DIRECTORY_SEPARATOR) { + if ('\\' === \DIRECTORY_SEPARATOR) { $exe = __DIR__.'/../Resources/bin/hiddeninput.exe'; // handle code running from a phar @@ -412,7 +422,7 @@ } try { - return call_user_func($question->getValidator(), $interviewer()); + return \call_user_func($question->getValidator(), $interviewer()); } catch (RuntimeException $e) { throw $e; } catch (\Exception $error) { @@ -438,7 +448,7 @@ if (file_exists('/usr/bin/env')) { // handle other OSs with bash/zsh/ksh/csh if available to hide the answer $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; - foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) { + foreach (['bash', 'zsh', 'ksh', 'csh'] as $sh) { if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) { self::$shell = $sh; break;