PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.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 All 257 releases
give / vendor / vendor-prefixed / stellarwp / validation / src / Rules / Boolean.php

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

67 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Vendors\StellarWP\Validation\Rules;
4
5 use Closure;
6 use Give\Vendors\StellarWP\Validation\Contracts\Sanitizer;
7 use Give\Vendors\StellarWP\Validation\Contracts\ValidatesOnFrontEnd;
8 use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule;
9
10 use const FILTER_NULL_ON_FAILURE;
11
12 class Boolean implements ValidationRule, ValidatesOnFrontEnd, Sanitizer
13 {
14 /**
15 * {@inheritDoc}
16 *
17 * @since 1.4.0
18 */
19 public static function id(): string
20 {
21 return 'boolean';
22 }
23
24 /**
25 * {@inheritDoc}
26 *
27 * @since 1.4.0
28 */
29 public static function fromString(?string $options = null): ValidationRule
30 {
31 return new self();
32 }
33
34 /**
35 * {@inheritDoc}
36 *
37 * @since 1.4.1 add is_bool check and FILTER_NULL_ON_FAILURE flag to prevent false positives
38 * @since 1.4.0
39 */
40 public function __invoke($value, Closure $fail, string $key, array $values)
41 {
42 if (!is_bool(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))) {
43 $fail(sprintf(__('%s must be a boolean', 'give'), '{field}'));
44 }
45 }
46
47 /**
48 * {@inheritDoc}
49 *
50 * @since 1.4.0
51 */
52 public function serializeOption()
53 {
54 return null;
55 }
56
57 /**
58 * {@inheritDoc}
59 *
60 * @since 1.4.0
61 */
62 public function sanitize($value)
63 {
64 return filter_var($value, FILTER_VALIDATE_BOOLEAN);
65 }
66 }
67