Final Class Yiisoft\Validator\Rule\StringValueHandler
| Inheritance | Yiisoft\Validator\Rule\StringValueHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
Validates that the value is a string.
See also Yiisoft\Validator\Rule\StringValue.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Validator\Rule\StringValueHandler |
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($value, RuleInterface $rule, ValidationContext $context): Result
{
if (!$rule instanceof StringValue) {
throw new UnexpectedRuleException(StringValue::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.