- md5
- 88e75e25976f1ec3dfce0f442980ee7a
- sha1
- 73803071187985b7b81f558d13c725fb1442eb27
- sha256
- 201a3ac3fdd77e5e529dfb2fe5dd33c7ff6b044cfbbc352e977651057e4734cd
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Question;
/**
* Represents a yes/no question.
*
* @author Fabien Potencier <[email protected]>
*/
class ConfirmationQuestion extends Question
{
private string $trueAnswerRegex;
/**
* @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->trueAnswerRegex = $trueAnswerRegex;
$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;
};
}
}
The same content is in 108 releases, Joomla 5.0.0-alpha1 to 6.0.0-alpha3. See them all, or every version of this file.