Final Class Yiisoft\Validator\Rule\StringValueHandler
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Validates that the value is a string.
See also Yiisoft\
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\ |
Method Details
| public Yiisoft\ | ||
| $value | mixed | |
| $rule | Yiisoft\ |
|
| $context | Yiisoft\ |
|
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();
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.