Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/console/Helper/QuestionHelper.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | c2387f117808 |
line wrap: on
line diff
--- a/vendor/symfony/console/Helper/QuestionHelper.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/console/Helper/QuestionHelper.php Mon Apr 23 09:46:53 2018 +0100 @@ -13,11 +13,12 @@ use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Exception\RuntimeException; +use Symfony\Component\Console\Formatter\OutputFormatter; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\StreamableInputInterface; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Question\ChoiceQuestion; @@ -35,10 +36,6 @@ /** * Asks a question to the user. * - * @param InputInterface $input An InputInterface instance - * @param OutputInterface $output An OutputInterface instance - * @param Question $question The question to ask - * * @return mixed The user answer * * @throws RuntimeException If there is no data to read in the input stream @@ -50,6 +47,12 @@ } if (!$input->isInteractive()) { + if ($question instanceof ChoiceQuestion) { + $choices = $question->getChoices(); + + return $choices[$question->getDefault()]; + } + return $question->getDefault(); } @@ -82,7 +85,7 @@ */ public function setInputStream($stream) { - @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::setStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED); + @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)) { throw new InvalidArgumentException('Input stream must be a valid resource.'); @@ -102,7 +105,7 @@ public function getInputStream() { if (0 === func_num_args() || func_get_arg(0)) { - @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::getStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED); + @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); } return $this->inputStream; @@ -117,11 +120,16 @@ } /** + * Prevents usage of stty. + */ + public static function disableStty() + { + self::$stty = false; + } + + /** * Asks the question to the user. * - * @param OutputInterface $output - * @param Question $question - * * @return bool|mixed|null|string * * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden @@ -153,7 +161,7 @@ $ret = trim($ret); } } else { - $ret = trim($this->autocomplete($output, $question, $inputStream)); + $ret = trim($this->autocomplete($output, $question, $inputStream, is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false))); } $ret = strlen($ret) > 0 ? $ret : $question->getDefault(); @@ -167,9 +175,6 @@ /** * Outputs the question prompt. - * - * @param OutputInterface $output - * @param Question $question */ protected function writePrompt(OutputInterface $output, Question $question) { @@ -194,9 +199,6 @@ /** * Outputs an error message. - * - * @param OutputInterface $output - * @param \Exception $error */ protected function writeError(OutputInterface $output, \Exception $error) { @@ -215,12 +217,12 @@ * @param OutputInterface $output * @param Question $question * @param resource $inputStream + * @param array $autocomplete * * @return string */ - private function autocomplete(OutputInterface $output, Question $question, $inputStream) + private function autocomplete(OutputInterface $output, Question $question, $inputStream, array $autocomplete) { - $autocomplete = $question->getAutocompleterValues(); $ret = ''; $i = 0; @@ -248,7 +250,7 @@ $output->write("\033[1D"); } - if ($i === 0) { + if (0 === $i) { $ofs = -1; $matches = $autocomplete; $numMatches = count($matches); @@ -316,7 +318,7 @@ // Save cursor position $output->write("\0337"); // Write highlighted text - $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>'); + $output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $i)).'</hl>'); // Restore cursor position $output->write("\0338"); } @@ -378,7 +380,7 @@ } if (false !== $shell = $this->getShell()) { - $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword'; + $readCmd = 'csh' === $shell ? 'set mypassword = $<' : 'read -r mypassword'; $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); $value = rtrim(shell_exec($command)); $output->writeln(''); @@ -460,6 +462,6 @@ exec('stty 2>&1', $output, $exitcode); - return self::$stty = $exitcode === 0; + return self::$stty = 0 === $exitcode; } }