Final Class Yiisoft\Validator\Rule\CountHandler
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
| Uses Traits | Yiisoft\ |
Validates that the value contains certain number of items.
Can be applied to arrays or classes implementing {@see \
See also Yiisoft\
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 Count) {
throw new UnexpectedRuleException(Count::class, $rule);
}
$result = new Result();
/** @var mixed $value */
if (!is_countable($value)) {
$result->addError($rule->getIncorrectInputMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($value),
]);
return $result;
}
$count = count($value);
$this->validateCountableLimits($rule, $context, $count, $result);
return $result;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.