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

Breadcrumb

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

class ConfirmationQuestion

Represents a yes/no question.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\Console\Question\Question
    • class \Symfony\Component\Console\Question\ConfirmationQuestion extends \Symfony\Component\Console\Question\Question

Expanded class hierarchy of ConfirmationQuestion

3 files declare their use of ConfirmationQuestion
GenerateTheme.php in core/lib/Drupal/Core/Command/GenerateTheme.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 {
    
    /**
     * @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(string $question, bool $default = true, string $trueAnswerRegex = '/^y/i') {
        parent::__construct($question, $default);
        $this->setNormalizer($this->getDefaultNormalizer());
    }
    
    /**
     * Returns the default answer normalizer.
     */
    private function getDefaultNormalizer() : callable {
        $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

Title Sort descending Modifiers Object type Summary Overriden Title
ConfirmationQuestion::getDefaultNormalizer private function Returns the default answer normalizer.
ConfirmationQuestion::__construct public function Overrides Question::__construct
Question::$attempts private property
Question::$autocompleterCallback private property
Question::$hidden private property
Question::$hiddenFallback private property
Question::$multiline private property
Question::$normalizer private property
Question::$trimmable private property
Question::$validator private property
Question::getAutocompleterCallback public function Gets the callback function used for the autocompleter.
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 cannot be hidden, whether to fallback on non-hidden question or not.
Question::isMultiline public function Returns whether the user response accepts newline characters.
Question::isTrimmable public function
Question::setAutocompleterCallback public function Sets the callback function used for the autocompleter.
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 cannot be hidden.
Question::setMaxAttempts public function Sets the maximum number of attempts.
Question::setMultiline public function Sets whether the user response should accept newline characters.
Question::setNormalizer public function Sets a normalizer for the response.
Question::setTrimmable public function
Question::setValidator public function Sets a validator for the question.
RSS feed
Powered by Drupal