File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,12 @@ The defined set can then be used in rules using `RuleSet::useDefined`.
95
95
}
96
96
```
97
97
98
+ To concatenate a defined rule set you can call concatDefined with the rule set's name.
99
+
100
+ ``` php
101
+ RuleSet::create()->required()->concatDefined('existing_email');
102
+ ```
103
+
98
104
#### requiredIfAll
99
105
100
106
Accepts multiple ` RequiredIf ` rules and only marks as required if all return true.
Original file line number Diff line number Diff line change @@ -63,6 +63,16 @@ public function concat(...$rule): self
63
63
return static ::create ([...$ this ->rules , ...$ rule ]);
64
64
}
65
65
66
+ /**
67
+ * Append all rules from a defined rule set.
68
+ *
69
+ * @param string $name
70
+ */
71
+ public function concatDefined (string $ name ): self
72
+ {
73
+ return $ this ->concat (...static ::useDefined ($ name )->toArray ());
74
+ }
75
+
66
76
/**
67
77
* Append a rule to the end of the rule set.
68
78
*
Original file line number Diff line number Diff line change @@ -76,4 +76,16 @@ public function testThrowInvalidArgumentExceptionOnUnknownDefinition(): void
76
76
// Assert
77
77
// No assertions, only expectations.
78
78
}
79
+
80
+ public function testConcatDefinedRuleSet (): void
81
+ {
82
+ // Arrange
83
+ RuleSet::define ('user.email ' , RuleSet::create ()->email ());
84
+
85
+ // Act
86
+ $ ruleSet = RuleSet::create ()->required ()->concatDefined ('user.email ' );
87
+
88
+ // Assert
89
+ $ this ->assertSame (['required ' , 'email ' ], $ ruleSet ->toArray ());
90
+ }
79
91
}
You can’t perform that action at this time.
0 commit comments