validator icon indicating copy to clipboard operation
validator copied to clipboard

Allow use callable rules into `Nested`

Open vjik opened this issue 2 years ago • 2 comments

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.

vjik avatar Jun 22 '23 17:06 vjik

Can you use this instead?

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

BoShurik avatar Jun 22 '23 17:06 BoShurik

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.

vjik avatar Jun 22 '23 17:06 vjik