1010use Yiisoft \Validator \BeforeValidationInterface ;
1111use Yiisoft \Validator \Rule \Trait \BeforeValidationTrait ;
1212use Yiisoft \Validator \Rule \Trait \RuleNameTrait ;
13+ use Yiisoft \Validator \Rule \Trait \SkipOnEmptyTrait ;
1314use Yiisoft \Validator \RuleInterface ;
1415use Yiisoft \Validator \SerializableRuleInterface ;
16+ use Yiisoft \Validator \SkipOnEmptyInterface ;
1517use Yiisoft \Validator \ValidationContext ;
1618
1719/**
1820 * Validates an array by checking each of its elements against a set of rules.
1921 */
2022#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE )]
21- final class Each implements SerializableRuleInterface, BeforeValidationInterface
23+ final class Each implements SerializableRuleInterface, BeforeValidationInterface, SkipOnEmptyInterface
2224{
2325 use BeforeValidationTrait;
2426 use RuleNameTrait;
27+ use SkipOnEmptyTrait;
2528
2629 public function __construct (
2730 /**
@@ -30,18 +33,17 @@ public function __construct(
3033 private iterable $ rules = [],
3134 private string $ incorrectInputMessage = 'Value must be array or iterable. ' ,
3235 private string $ message = '{error} {value} given. ' ,
33- private bool $ skipOnEmpty = false ,
36+
3437 /**
35- * @var callable
38+ * @var bool| callable|null
3639 */
37- private $ skipOnEmptyCallback = null ,
40+ private $ skipOnEmpty = null ,
3841 private bool $ skipOnError = false ,
3942 /**
4043 * @var Closure(mixed, ValidationContext):bool|null
4144 */
4245 private ?Closure $ when = null ,
4346 ) {
44- $ this ->initSkipOnEmptyProperties ($ skipOnEmpty , $ skipOnEmptyCallback );
4547 }
4648
4749 /**
@@ -93,7 +95,7 @@ public function getOptions(): array
9395 'message ' => [
9496 'message ' => $ this ->getMessage (),
9597 ],
96- 'skipOnEmpty ' => $ this ->skipOnEmpty ,
98+ 'skipOnEmpty ' => $ this ->getSkipOnEmptyOption () ,
9799 'skipOnError ' => $ this ->skipOnError ,
98100 'rules ' => $ arrayOfRules ,
99101 ];
0 commit comments