Final Class Yiisoft\Validator\Rule\Type\BooleanTypeHandler
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
A handler for {@see BooleanType} rule. Validates that the value has a boolean type (strictly) - {@link https://www.php.net/manual/en/language.types.boolean.php}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\ |
Method Details
| public Yiisoft\ | ||
| $value | mixed | |
| $rule | Yiisoft\ |
|
| $context | Yiisoft\ |
|
public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
{
if (!$rule instanceof BooleanType) {
throw new UnexpectedRuleException(BooleanType::class, $rule);
}
if (!is_bool($value)) {
return (new Result())->addError($rule->getMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($value),
]);
}
return new Result();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.