You are here

class ConfirmationQuestion in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Question/ConfirmationQuestion.php \Symfony\Component\Console\Question\ConfirmationQuestion

Represents a yes/no question.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of ConfirmationQuestion

3 files declare their use of ConfirmationQuestion
QuestionHelperTest.php in vendor/symfony/console/Tests/Helper/QuestionHelperTest.php
SymfonyQuestionHelper.php in vendor/symfony/console/Helper/SymfonyQuestionHelper.php
SymfonyStyle.php in vendor/symfony/console/Style/SymfonyStyle.php

File

vendor/symfony/console/Question/ConfirmationQuestion.php, line 19

Namespace

Symfony\Component\Console\Question
View source
class ConfirmationQuestion extends Question {
  private $trueAnswerRegex;

  /**
   * Constructor.
   *
   * @param string $question        The question to ask to the user
   * @param bool   $default         The default answer to return, true or false
   * @param string $trueAnswerRegex A regex to match the "yes" answer
   */
  public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i') {
    parent::__construct($question, (bool) $default);
    $this->trueAnswerRegex = $trueAnswerRegex;
    $this
      ->setNormalizer($this
      ->getDefaultNormalizer());
  }

  /**
   * Returns the default answer normalizer.
   *
   * @return callable
   */
  private function getDefaultNormalizer() {
    $default = $this
      ->getDefault();
    $regex = $this->trueAnswerRegex;
    return function ($answer) use ($default, $regex) {
      if (is_bool($answer)) {
        return $answer;
      }
      $answerIsTrue = (bool) preg_match($regex, $answer);
      if (false === $default) {
        return $answer && $answerIsTrue;
      }
      return !$answer || $answerIsTrue;
    };
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfirmationQuestion::$trueAnswerRegex private property
ConfirmationQuestion::getDefaultNormalizer private function Returns the default answer normalizer.
ConfirmationQuestion::__construct public function Constructor. Overrides Question::__construct
Question::$attempts private property
Question::$autocompleterValues private property
Question::$default private property
Question::$hidden private property
Question::$hiddenFallback private property
Question::$normalizer private property
Question::$question private property
Question::$validator private property
Question::getAutocompleterValues public function Gets values for the autocompleter.
Question::getDefault public function Returns the default answer.
Question::getMaxAttempts public function Gets the maximum number of attempts.
Question::getNormalizer public function Gets the normalizer for the response.
Question::getQuestion public function Returns the question.
Question::getValidator public function Gets the validator for the question.
Question::isAssoc protected function
Question::isHidden public function Returns whether the user response must be hidden.
Question::isHiddenFallback public function In case the response can not be hidden, whether to fallback on non-hidden question or not.
Question::setAutocompleterValues public function Sets values for the autocompleter.
Question::setHidden public function Sets whether the user response must be hidden or not.
Question::setHiddenFallback public function Sets whether to fallback on non-hidden question if the response can not be hidden.
Question::setMaxAttempts public function Sets the maximum number of attempts.
Question::setNormalizer public function Sets a normalizer for the response.
Question::setValidator public function Sets a validator for the question.