Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit 803a9bb

Browse files
author
VladimirBerdnik
committed
Add 'sometimes' rule modifier
1 parent f90bacc commit 803a9bb

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/Rule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @method static GenericRuleSet min($minValue) The field under validation must have a minimum value. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.
2525
* @method static GenericRuleSet max($maxValue) The field under validation must be less than or equal to a maximum value. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.
2626
* @method static GenericRuleSet inArray(string $anotherField) The field under validation must exist in $anotherField's values.
27+
* @method static GenericRuleSet sometimes() Run validation checks against a field only if that field is present in the input array.
2728
* @method static GenericRuleSet requiredWith(string ...$otherFields) This field is required, if another field has value
2829
* @method static GenericRuleSet requiredWithAll(string ...$otherFields) The field under validation must be present and not empty only if all of the other specified fields are present.
2930
* @method static GenericRuleSet requiredWithout(string ...$otherFields) This field is required, if another field has no value

src/RuleSet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class RuleSet implements IRule
4949
'max',
5050
'between',
5151
'size',
52+
'sometimes',
5253
];
5354

5455
/** @var array */

src/SimpleRules.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,13 @@ public function size(int $value)
117117
{
118118
return $this->appendIfNotExists("size:$value");
119119
}
120+
121+
/**
122+
* Run validation checks against a field only if that field is present in the input array.
123+
* @return static
124+
*/
125+
public function sometimes()
126+
{
127+
return $this->appendIfNotExists("sometimes");
128+
}
120129
}

0 commit comments

Comments
 (0)