function ConsoleIO::select
@inheritDoc
Overrides IOInterface::select
File
-
vendor/
composer/ composer/ src/ Composer/ IO/ ConsoleIO.php, line 302
Class
- ConsoleIO
- The Input/Output helper.
Namespace
Composer\IOCode
public function select($question, $choices, $default, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false) {
/** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */
$helper = $this->helperSet
->get('question');
$question = new ChoiceQuestion($question, $choices, $default);
$question->setMaxAttempts($attempts ?: null);
// IOInterface requires false, and Question requires null or int
$question->setErrorMessage($errorMessage);
$question->setMultiselect($multiselect);
$result = $helper->ask($this->input, $this->getErrorOutput(), $question);
$isAssoc = (bool) \count(array_filter(array_keys($choices), 'is_string'));
if ($isAssoc) {
return $result;
}
if (!is_array($result)) {
return (string) array_search($result, $choices, true);
}
$results = [];
foreach ($choices as $index => $choice) {
if (in_array($choice, $result, true)) {
$results[] = (string) $index;
}
}
return $results;
}