function StrictConfirmationQuestion::getDefaultNormalizer
Returns the default answer normalizer.
1 call to StrictConfirmationQuestion::getDefaultNormalizer()
- StrictConfirmationQuestion::__construct in vendor/
composer/ composer/ src/ Composer/ Question/ StrictConfirmationQuestion.php - Constructor.s
File
-
vendor/
composer/ composer/ src/ Composer/ Question/ StrictConfirmationQuestion.php, line 54
Class
- StrictConfirmationQuestion
- Represents a yes/no question Enforces strict responses rather than non-standard answers counting as default Based on Symfony\Component\Console\Question\ConfirmationQuestion
Namespace
Composer\QuestionCode
private function getDefaultNormalizer() : callable {
$default = $this->getDefault();
$trueRegex = $this->trueAnswerRegex;
$falseRegex = $this->falseAnswerRegex;
return static function ($answer) use ($default, $trueRegex, $falseRegex) {
if (is_bool($answer)) {
return $answer;
}
if (empty($answer) && !empty($default)) {
return $default;
}
if (Preg::isMatch($trueRegex, $answer)) {
return true;
}
if (Preg::isMatch($falseRegex, $answer)) {
return false;
}
return null;
};
}