Final Class Yiisoft\Validator\Rule\LengthHandler
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
| Uses Traits | Yiisoft\ |
Validates that the value is a string of a certain length.
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 Length) {
throw new UnexpectedRuleException(Length::class, $rule);
}
$result = new Result();
if (!is_string($value)) {
$result->addError($rule->getIncorrectInputMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($value),
]);
return $result;
}
$length = mb_strlen($value, $rule->getEncoding());
$this->validateCountableLimits($rule, $context, $length, $result);
return $result;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.