Final Class Yiisoft\Validator\Rule\CallbackHandler
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Validates a value using a callback.
See also Yiisoft\
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\ |
Method Details
| public Yiisoft\ | ||
| $value | mixed | |
| $rule | Yiisoft\ |
|
| $context | Yiisoft\ |
|
| throws | Yiisoft\ |
|
|---|---|---|
public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
{
if (!$rule instanceof Callback) {
throw new UnexpectedRuleException(Callback::class, $rule);
}
$callback = $rule->getCallback();
if ($callback === null) {
throw new InvalidArgumentException('Using method outside of attribute scope is prohibited.');
}
$result = $callback($value, $rule, $context);
if (!$result instanceof Result) {
throw new InvalidCallbackReturnTypeException($result);
}
return $result;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.