9
9
use Brick \Math \BigNumber ;
10
10
use DateTimeInterface ;
11
11
use Illuminate \Contracts \Support \Arrayable ;
12
- use Illuminate \Contracts \Validation \InvokableRule ;
13
- use Illuminate \Contracts \Validation \Rule as RuleContract ;
14
- use Illuminate \Contracts \Validation \ValidationRule ;
15
- use Illuminate \Validation \ConditionalRules ;
16
12
use Illuminate \Validation \Rules \Password ;
17
13
use Illuminate \Validation \Rules \RequiredIf ;
18
14
use IteratorAggregate ;
19
- use Stringable ;
20
15
use UnitEnum ;
21
16
22
17
/**
23
- * @implements Arrayable<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string>
24
- * @implements IteratorAggregate<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string>
18
+ * @phpstan-import-type RuleType from Rule
19
+ * @phpstan-import-type RuleSetDefinition from Rule
20
+ * @implements Arrayable<array-key, RuleType>
21
+ * @implements IteratorAggregate<array-key, RuleType>
25
22
*/
26
23
class RuleSet implements Arrayable, IteratorAggregate
27
24
{
28
25
/**
29
- * @param array<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string > $rules
26
+ * @param array<array-key, RuleType > $rules
30
27
*/
31
28
final public function __construct (protected array $ rules = [])
32
29
{
33
30
//
34
31
}
35
32
36
33
/**
37
- * @return ArrayIterator<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string >
34
+ * @return ArrayIterator<array-key, RuleType >
38
35
*/
39
36
public function getIterator (): ArrayIterator
40
37
{
@@ -44,7 +41,7 @@ public function getIterator(): ArrayIterator
44
41
/**
45
42
* Get the rule set as an array.
46
43
*
47
- * @return array<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string >
44
+ * @return array<array-key, RuleType >
48
45
*/
49
46
public function toArray (): array
50
47
{
@@ -54,7 +51,7 @@ public function toArray(): array
54
51
/**
55
52
* Create a new rule set.
56
53
*
57
- * @param array<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string > $rules
54
+ * @param array<array-key, RuleType > $rules
58
55
*/
59
56
public static function create (array $ rules = []): self
60
57
{
@@ -80,7 +77,7 @@ public static function useDefined(string|BackedEnum|UnitEnum $name): RuleSet
80
77
/**
81
78
* Append one or more rules to the end of the rule set.
82
79
*
83
- * @param RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string $rule
80
+ * @param RuleType $rule
84
81
*/
85
82
public function concat (...$ rule ): self
86
83
{
@@ -98,7 +95,7 @@ public function concatDefined(string $name): self
98
95
/**
99
96
* Append a rule to the end of the rule set.
100
97
*
101
- * @param RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string $rule
98
+ * @param RuleType $rule
102
99
*/
103
100
public function rule (mixed $ rule ): self
104
101
{
@@ -205,6 +202,18 @@ public function alphaNum(?bool $limitToAscii = null): self
205
202
return $ this ->rule (Rule::alphaNum ($ limitToAscii ));
206
203
}
207
204
205
+ /**
206
+ * The `anyOf` validation rule allows you to specify that the field under validation must satisfy any of the given
207
+ * validation rulesets.
208
+ *
209
+ * @link https://laravel.com/docs/12.x/validation#rule-anyof
210
+ * @param array<array-key, RuleSetDefinition> $ruleSets
211
+ */
212
+ public function anyOf (array $ ruleSets ): self
213
+ {
214
+ return $ this ->rule (Rule::anyOf ($ ruleSets ));
215
+ }
216
+
208
217
/**
209
218
* The field under validation must be a PHP *array*.
210
219
*
@@ -759,6 +768,16 @@ public function inArray(string $anotherField): self
759
768
return $ this ->rule (Rule::inArray ($ anotherField ));
760
769
}
761
770
771
+ /**
772
+ * The field under validation must be an array having at least one of the given *values* as a key within the array.
773
+ *
774
+ * @link https://laravel.com/docs/12.x/validation#rule-in-array-keys
775
+ */
776
+ public function inArrayKeys (string ...$ value ): self
777
+ {
778
+ return $ this ->rule (Rule::inArrayKeys (...$ value ));
779
+ }
780
+
762
781
/**
763
782
* The field under validation must be an integer.
764
783
*
@@ -1505,8 +1524,8 @@ public function uuid(): self
1505
1524
* Create a new conditional rule set.
1506
1525
*
1507
1526
* @param bool|callable(\Illuminate\Support\Fluent<array-key, mixed>): bool $condition
1508
- * @param array<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string >|string|RuleSet $rules
1509
- * @param array<array-key, RuleContract|InvokableRule|ValidationRule|ConditionalRules|Stringable|string >|string|RuleSet $defaultRules
1527
+ * @param array<array-key, RuleType >|string|RuleSet $rules
1528
+ * @param array<array-key, RuleType >|string|RuleSet $defaultRules
1510
1529
*/
1511
1530
public function when (mixed $ condition , array |string |RuleSet $ rules , array |string |RuleSet $ defaultRules = []): self
1512
1531
{
0 commit comments