src/Console/Component/Prompter.php
public function ask(string $prompt, array $validAnswers = [], string $default = null)
    {
        if ($validAnswers) {
            $answers = [];
            foreach ($validAnswers as $v) {
                if ($default && $default === $v) {
                    $answers[] = '[' . $v . ']';
                } else {
                    $answers[] = $v;
                }
            }
            $prompt .= ' (' . implode('/', $answers) . ')';
        }

        $prompt .= ' ';

        if ($this->style) {
            echo $this->formatter->getStartMark($this->style);
        }

        $answer = null;
        while (true) {
            $answer = trim($this->console->readLine($prompt));
            if ($validAnswers) {
                if (in_array($answer, $validAnswers, true)) {
                    break;
                }

                if (trim($answer) === '' && $default) {
                    $answer = $default;
                    break;
                }
                continue;
            }
            break;
        }

        if ($this->style) {
            echo $this->formatter->getClearMark();
        }

        return $answer;
    }
public function ask(string $prompt, array $validAnswers = [], string $default = null)
    {
        if ($validAnswers) {
            $answers = [];
            foreach ($validAnswers as $v) {
                if ($default && $default === $v) {
                    $answers[] = '[' . $v . ']';
                } else {
                    $answers[] = $v;
                }
            }
            $prompt .= ' (' . implode('/', $answers) . ')';
        }

        $prompt .= ' ';

        if ($this->style) {
            echo $this->formatter->getStartMark($this->style);
        }

        $answer = null;
        while (true) {
            $answer = trim($this->console->readLine($prompt));
            if ($validAnswers) {
                if (in_array($answer, $validAnswers, true)) {
                    break;
                }

                if (trim($answer) === '' && $default) {
                    $answer = $default;
                    break;
                }
                continue;
            }
            break;
        }

        if ($this->style) {
            echo $this->formatter->getClearMark();
        }

        return $answer;
    }
public function ask ( string $ prompt , array $ validAnswers = [ ] , string $ default = null ) { if ( $ validAnswers ) { $ answers = [ ] ; foreach ( $ validAnswers as $ v ) { if ( $ default && $ default === $ v ) { $ answers [ ] = '[' . $ v . ']' ; } else { $ answers [ ] = $ v ; } } $ prompt .= ' (' . implode ( '/' , $ answers ) . ')' ; } $ prompt .= ' ' ; if ( $ this -> style ) { echo $ this -> formatter -> getStartMark ( $ this -> style ) ; } $ answer = null ; while ( true ) { $ answer = trim ( $ this -> console -> readLine ( $ prompt ) ) ; if ( $ validAnswers ) { if ( in_array ( $ answer , $ validAnswers , true ) ) { break ; } if ( trim ( $ answer ) === '' && $ default ) { $ answer = $ default ; break ; } continue ; } break ; } if ( $ this -> style ) { echo $ this -> formatter -> getClearMark ( ) ; } return $ answer ; }
Show prompt with message, you can provide valid options
for the simple validation.

@param string      $prompt
@param array       $validAnswers an array of valid values (optional)
@param string|null $default

@return null|string
Show prompt with message you can provide valid options for the simple validation .