PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
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 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / DonationForms / Rules / ArrayRule.php
ArrayRule.php
63 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Give\DonationForms\Rules;
3
4 use Closure;
5 use Give\Vendors\StellarWP\Validation\Contracts\Sanitizer;
6 use Give\Vendors\StellarWP\Validation\Contracts\ValidatesOnFrontEnd;
7 use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule;
8
9 class ArrayRule implements ValidationRule, ValidatesOnFrontEnd, Sanitizer
10 {
11 /**
12 * @var boolean
13 */
14 private $sanitizeAsString;
15
16 public function __construct($useSanitizer = false)
17 {
18 $this->sanitizeAsString = $useSanitizer;
19 }
20
21 /**
22 * @since 3.0.0
23 */
24 public static function id(): string
25 {
26 return 'array';
27 }
28
29 /**
30 * @since 3.0.0
31 */
32 public static function fromString(string $options = null): ValidationRule
33 {
34 return new self();
35 }
36
37 /**
38 * @since 3.0.0
39 */
40 public function __invoke($value, Closure $fail, string $key, array $values)
41 {
42 if (!empty($value) && !is_array($value)) {
43 $fail(sprintf(__('%s must be an array', 'give'), '{field}'));
44 }
45 }
46
47 /**
48 * @since 3.0.0
49 */
50 public function sanitize($value): string
51 {
52 return $this->sanitizeAsString ? implode(' | ', $value) : $value;
53 }
54
55 /**
56 * @since 3.0.0
57 */
58 public function serializeOption()
59 {
60 return null;
61 }
62 }
63