You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| AndRule |`new AndRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))`| Expects `n` ValidationRule, ensures all pass |
413
+
| OrRule |`new OrRule(new BetweenRule(2.4, 5.5), new LowerThanRule(5))`| Expects `n` ValidationRule, ensures at least one passes |
414
+
| BetweenRule |`new BetweenRule(2.4, 5.5)`| For INT and FLOAT, check that the value is between min and max |
415
+
| InRule |`new InRule("it","en","de")`| Expects the value to be validated to be in that equal to one of the `n` params |
416
+
| InstanceOfRule |`new InstanceOfRule(Theme::class)`| For non primitive casts, checks the instance of the value's class to validate. Tip: goes along well with the `OrRule`|
417
+
| IsRule |`new IsRule(Type::ITERABLE)`| Expects a `Matteoc99\LaravelPreference\Enums\Type` Enum. Checks e.g. if the value is iterable |
418
+
| LowerThanRule |`new LowerThanRule(5)`| For INT and FLOAT, check that the value to be validated is less than the one passed in the constructor |
419
+
420
+
### Custom Rules
373
421
374
422
implement `ValidationRule`
375
423
@@ -475,7 +523,7 @@ which can all be accessed via the route name: {prefix}.{scope}.{group}.{index/ge
475
523
`group`: A mapping of group names to their corresponding Enum classes. See config below
476
524
`scope`: A mapping of scope names to their corresponding Eloquent model. See config below
477
525
478
-
### Example:
526
+
### Config Example:
479
527
480
528
```php
481
529
'routes' => [
@@ -511,17 +559,14 @@ will result in the following **route names**:
511
559
> [!NOTE]
512
560
> Examples are with scope `user` and group `general`
513
561
514
-
515
562
#### INDEX
516
563
517
-
518
564
- Route Name: custom_prefix.user.general.index
519
565
- Url params: `scope_id`
520
566
- Equivalent to: `$user->getPreferences(General::class)`
[newOrRule(newBetweenRule(2.4, 5.5), newLowerThanRule(2)), 3, true, 'Expected OrRule to pass when the first rule passes.'],
22
+
[newOrRule(newBetweenRule(2.4, 5.5), newLowerThanRule(2)), 1, true, 'Expected OrRule to pass when the second rule passes.'],
23
+
[newOrRule(newBetweenRule(2.4, 5.5), newLowerThanRule(2)), 6, false, 'Expected OrRule to fail when neither rule passes.'],
24
+
[newOrRule(newInstanceOfRule(Theme::class), newIsRule(Type::ITERABLE)), Theme::LIGHT, true, 'Expected OrRule to pass with an instance of SomeClass.'],
25
+
[newOrRule(newInstanceOfRule(Theme::class), newIsRule(Type::ITERABLE)), [], true, 'Expected OrRule to pass with an iterable (array).'],
26
+
[newOrRule(newLowerThanRule(5), newBetweenRule(10, 20)), 25, false, 'Expected OrRule to fail when all rules fail.'],
27
+
[newOrRule(newAndRule(newBetweenRule(5, 15), newLowerThanRule(20)), newInRule("it", "en", "de")), 10, true, 'Expected OrRule to pass with nested AndRule conditions met.'],
28
+
[newOrRule(newAndRule(newBetweenRule(5, 15), newLowerThanRule(20)), newInRule("it", "en", "de")), "en", true, 'Expected OrRule to pass with value in InRule parameters.'],
29
+
[newOrRule(newAndRule(newBetweenRule(5, 15), newLowerThanRule(20)), newInRule("it", "en", "de")), "fr", false, 'Expected OrRule to fail when nested conditions are not met.'],
30
+
];
31
+
}
32
+
33
+
publicstaticfunctionandRuleProvider(): array
34
+
{
35
+
return [
36
+
[newAndRule(newBetweenRule(2.4, 5.5), newLowerThanRule(6)), 3, true, 'Expected AndRule to pass when all conditions are met.'],
37
+
[newAndRule(newBetweenRule(2.4, 5.5), newLowerThanRule(3)), 4, false, 'Expected AndRule to fail when one condition fails.'],
38
+
[newAndRule(newBetweenRule(2.4, 5.5), newLowerThanRule(3)), 6, false, 'Expected AndRule to fail when both conditions fail.'],
39
+
[newAndRule(newInstanceOfRule(Theme::class), newIsRule(Type::ITERABLE)), Theme::LIGHT, false, 'Expected AndRule to fail since SomeClass is not iterable.'],
40
+
[newAndRule(newInstanceOfRule(Theme::class), newIsRule(Type::ITERABLE)), [], false, 'Expected AndRule to fail since array is not an instance of SomeClass.'],
41
+
[newAndRule(newOrRule(newBetweenRule(10, 20), newInRule("it", "en", "de")), newLowerThanRule(15)), 12, true, 'Expected AndRule to pass with nested OrRule condition met and value less than 15.'],
42
+
[newAndRule(newBetweenRule(2.4, 5.5), newLowerThanRule(5.5)), 5.4, true, 'Expected AndRule to pass at the edge of the range.'],
0 commit comments