PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
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 / Framework / FieldsAPI / Concerns / ValidationRules.php
ValidationRules.php
97 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\FieldsAPI\Concerns;
4
5 use JsonSerializable;
6
7 /**
8 * @since 2.12.0
9 */
10 class ValidationRules implements JsonSerializable
11 {
12
13 /** @var array */
14 protected $rules;
15
16 /**
17 * ValidationRules constructor.
18 *
19 * @param array $rules
20 */
21 public function __construct($rules = [])
22 {
23 $this->rules = $rules;
24 }
25
26 /**
27 * Set a rule.
28 *
29 * @since 2.12.0
30 *
31 * @param string $rule
32 * @param mixed $value
33 *
34 * @return $this
35 */
36 public function rule($rule, $value)
37 {
38 $this->rules[$rule] = $value;
39
40 return $this;
41 }
42
43 /**
44 * Get a rule.
45 *
46 * @since 2.12.0
47 *
48 * @param string $rule
49 *
50 * @return mixed
51 */
52 public function getRule($rule)
53 {
54 return array_key_exists($rule, $this->rules)
55 ? $this->rules[$rule]
56 : null;
57 }
58
59 /**
60 * Forget a rule.
61 *
62 * @since 2.12.0
63 *
64 * @param string $rule
65 *
66 * @return $this
67 */
68 public function forgetRule($rule)
69 {
70 if (array_key_exists($rule, $this->rules)) {
71 unset($this->rules[$rule]);
72 }
73
74 return $this;
75 }
76
77 /**
78 * Get all the rules.
79 *
80 * @since 2.12.0
81 *
82 * @return array
83 */
84 public function all()
85 {
86 return $this->rules;
87 }
88
89 /**
90 * {@inheritdoc}}
91 */
92 public function jsonSerialize()
93 {
94 return (object)$this->all();
95 }
96 }
97