yiisoft / validator

Yii validator library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
112 stars 39 forks source link

Allow use callable rules into `Nested` #611

Open vjik opened 1 year ago

vjik commented 1 year ago

For Example:

new Nested([
    'tag' => static fn() => (new Result())->addError('Too short.'),
]);

Now it's throw exception:

InvalidArgumentException: Every rule must be an instance of Yiisoft\Validator\RuleInterface, Closure given.
BoShurik commented 1 year ago

Can you use this instead?

new Nested([
    'tag' => new Callback(static fn() => (new Result())->addError('Too short.')),
]);
vjik commented 1 year ago

Can you use this instead?

new Nested([
    'tag' => new Callback(static fn() => (new Result())->addError('Too short.')),
]);

Yes, it's work. But my suggestion is more simpler and consistently with rules syntax that pass to Validator.