PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / vendor-prefixed / stellarwp / validation / src / Rules / Optional.php

Optional.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/vendor-prefixed/stellarwp/validation/src/Rules/Optional.php

55 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Give\Vendors\StellarWP\Validation\Rules;
6
7 use Closure;
8 use Give\Vendors\StellarWP\Validation\Commands\SkipValidationRules;
9 use Give\Vendors\StellarWP\Validation\Contracts\ValidatesOnFrontEnd;
10 use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule;
11
12 /**
13 * This rule marks a field as optional and skips further validation if the rule is either null or an empty string.
14 *
15 * @since 1.1.0
16 */
17 class Optional implements ValidationRule, ValidatesOnFrontEnd
18 {
19 /**
20 * @since 1.1.0
21 */
22 public static function id(): string
23 {
24 return 'optional';
25 }
26
27 /**
28 * @since 1.1.0
29 */
30 public static function fromString(?string $options = null): ValidationRule
31 {
32 return new self();
33 }
34
35 /**
36 * @since 1.1.0
37 *
38 * @return SkipValidationRules|void
39 */
40 public function __invoke($value, Closure $fail, string $key, array $values)
41 {
42 if ($value === null || $value === '') {
43 return new SkipValidationRules();
44 }
45 }
46
47 /**
48 * @since 1.1.0
49 */
50 public function serializeOption()
51 {
52 return null;
53 }
54 }
55