Abstracts
2 years ago
Boolean.php
2 years ago
Currency.php
2 years ago
DateTime.php
2 years ago
Email.php
2 years ago
Exclude.php
2 years ago
ExcludeIf.php
2 years ago
ExcludeUnless.php
2 years ago
In.php
2 years ago
InStrict.php
2 years ago
Integer.php
2 years ago
Max.php
2 years ago
Min.php
2 years ago
Nullable.php
2 years ago
NullableIf.php
2 years ago
NullableUnless.php
2 years ago
Numeric.php
2 years ago
Optional.php
2 years ago
OptionalIf.php
2 years ago
OptionalUnless.php
2 years ago
Required.php
2 years ago
Size.php
2 years ago
OptionalIf.php
44 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * |
| 5 | * Modified by impress-org on 30-October-2023 using Strauss. |
| 6 | * @see https://github.com/BrianHenryIE/strauss |
| 7 | */ |
| 8 | |
| 9 | declare(strict_types=1); |
| 10 | |
| 11 | namespace Give\Vendors\StellarWP\Validation\Rules; |
| 12 | |
| 13 | use Closure; |
| 14 | use Give\Vendors\StellarWP\Validation\Commands\SkipValidationRules; |
| 15 | use Give\Vendors\StellarWP\Validation\Rules\Abstracts\ConditionalRule; |
| 16 | |
| 17 | /** |
| 18 | * Mark the value as optional if the conditions pass |
| 19 | * |
| 20 | * @since 1.2.0 |
| 21 | * |
| 22 | * @see Optional |
| 23 | */ |
| 24 | class OptionalIf extends ConditionalRule |
| 25 | { |
| 26 | /** |
| 27 | * @since 1.2.0 |
| 28 | */ |
| 29 | public static function id(): string |
| 30 | { |
| 31 | return 'optionalIf'; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @since 1.2.0 |
| 36 | */ |
| 37 | public function __invoke($value, Closure $fail, string $key, array $values) |
| 38 | { |
| 39 | if (($value === '' || $value === null) && $this->conditions->passes($values)) { |
| 40 | return new SkipValidationRules(); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |