Final Class Yiisoft\Validator\Rule\Type\StringTypeHandler
| Inheritance | Yiisoft\Validator\Rule\Type\StringTypeHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
A handler for {@see StringType} rule. Validates that the value has string type - {@link https://www.php.net/manual/en/language.types.string.php}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Validator\Rule\Type\StringTypeHandler |
Method Details
| public Yiisoft\Validator\Result validate ( mixed $value, Yiisoft\Validator\RuleInterface $rule, Yiisoft\Validator\ValidationContext $context ) | ||
| $value | mixed | |
| $rule | Yiisoft\Validator\RuleInterface | |
| $context | Yiisoft\Validator\ValidationContext | |
public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
{
if (!$rule instanceof StringType) {
throw new UnexpectedRuleException(StringType::class, $rule);
}
if (!is_string($value)) {
return (new Result())->addError($rule->getMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($value),
]);
}
return new Result();
}
Signup or Login in order to comment.