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

Breadcrumb

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

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\Question

Code

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;
    };
}
RSS feed
Powered by Drupal