class ConfirmationQuestion in Zircon Profile 8
Same name and namespace in other branches
- 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
- class \Symfony\Component\Console\Question\Question
- class \Symfony\Component\Console\Question\ConfirmationQuestion
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\QuestionView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmationQuestion:: |
private | property | ||
ConfirmationQuestion:: |
private | function | Returns the default answer normalizer. | |
ConfirmationQuestion:: |
public | function |
Constructor. Overrides Question:: |
|
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
private | property | ||
Question:: |
public | function | Gets values for the autocompleter. | |
Question:: |
public | function | Returns the default answer. | |
Question:: |
public | function | Gets the maximum number of attempts. | |
Question:: |
public | function | Gets the normalizer for the response. | |
Question:: |
public | function | Returns the question. | |
Question:: |
public | function | Gets the validator for the question. | |
Question:: |
protected | function | ||
Question:: |
public | function | Returns whether the user response must be hidden. | |
Question:: |
public | function | In case the response can not be hidden, whether to fallback on non-hidden question or not. | |
Question:: |
public | function | Sets values for the autocompleter. | |
Question:: |
public | function | Sets whether the user response must be hidden or not. | |
Question:: |
public | function | Sets whether to fallback on non-hidden question if the response can not be hidden. | |
Question:: |
public | function | Sets the maximum number of attempts. | |
Question:: |
public | function | Sets a normalizer for the response. | |
Question:: |
public | function | Sets a validator for the question. |