use Symfony\Component\Console\Input\StreamableInputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Question\ChoiceQuestion;
+use Symfony\Component\Console\Question\Question;
/**
* The QuestionHelper class provides helpers to interact with the user.
}
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()) {
{
@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.');
}
*/
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);
}
/**
* 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
*/
$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);
$i = 0;
$ofs = -1;
$matches = $autocomplete;
- $numMatches = count($matches);
+ $numMatches = \count($matches);
$sttyMode = shell_exec('stty -g');
if (0 === $i) {
$ofs = -1;
$matches = $autocomplete;
- $numMatches = count($matches);
+ $numMatches = \count($matches);
} else {
$numMatches = 0;
}
$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) {
*/
private function getHiddenResponse(OutputInterface $output, $inputStream)
{
- if ('\\' === DIRECTORY_SEPARATOR) {
+ if ('\\' === \DIRECTORY_SEPARATOR) {
$exe = __DIR__.'/../Resources/bin/hiddeninput.exe';
// handle code running from a phar
}
try {
- return call_user_func($question->getValidator(), $interviewer());
+ return \call_user_func($question->getValidator(), $interviewer());
} catch (RuntimeException $e) {
throw $e;
} catch (\Exception $error) {