PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.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 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / FieldsAPI / Concerns / ValidationRules.php
ValidationRules.php
87 lines 1.2 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 /** @var array */
13 protected $rules;
14
15 /**
16 * ValidationRules constructor.
17 *
18 * @param array $rules
19 */
20 public function __construct( $rules = [] ) {
21 $this->rules = $rules;
22 }
23
24 /**
25 * Set a rule.
26 *
27 * @since 2.12.0
28 *
29 * @param string $rule
30 * @param mixed $value
31 * @return $this
32 */
33 public function rule( $rule, $value ) {
34 $this->rules[ $rule ] = $value;
35
36 return $this;
37 }
38
39 /**
40 * Get a rule.
41 *
42 * @since 2.12.0
43 *
44 * @param string $rule
45 * @return mixed
46 */
47 public function getRule( $rule ) {
48 return array_key_exists( $rule, $this->rules )
49 ? $this->rules[ $rule ]
50 : null;
51 }
52
53 /**
54 * Forget a rule.
55 *
56 * @since 2.12.0
57 *
58 * @param string $rule
59 * @return $this
60 */
61 public function forgetRule( $rule ) {
62 if ( array_key_exists( $rule, $this->rules ) ) {
63 unset( $this->rules[ $rule ] );
64 }
65
66 return $this;
67 }
68
69 /**
70 * Get all the rules.
71 *
72 * @since 2.12.0
73 *
74 * @return array
75 */
76 public function all() {
77 return $this->rules;
78 }
79
80 /**
81 * {@inheritdoc}}
82 */
83 public function jsonSerialize() {
84 return (object) $this->all();
85 }
86 }
87