Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ConsoleIO.php

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\IO

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal