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 / Concerns / HasValidationRules.php

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

124 lines 2.6 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\Concerns;
6
7 use Give\Vendors\StellarWP\Validation\Config;
8 use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule;
9 use Give\Vendors\StellarWP\Validation\ValidationRuleSet;
10
11 /**
12 * Apply this trait to a class to enable it to have validation rules. These rules may be passed to the front-end
13 * or used with the Validator to validate data.
14 *
15 * @since 1.0.0
16 */
17 trait HasValidationRules
18 {
19 /**
20 * @var ValidationRuleSet
21 */
22 protected $validationRules;
23
24 /**
25 * @since 1.0.0
26 */
27 public function __construct()
28 {
29 $this->validationRules = Config::getServiceContainer()->get(ValidationRuleSet::class);
30 }
31
32 /**
33 * @see ValidationRuleSet::rules()
34 *
35 * @since 1.0.0
36 */
37 public function rules(...$rules): self
38 {
39 $this->validationRules->rules(...$rules);
40
41 return $this;
42 }
43
44 /**
45 * @see ValidationRuleSet::hasRule()
46 *
47 * @since 1.0.0
48 */
49 public function hasRule(string $ruleId): bool
50 {
51 return $this->validationRules->hasRule($ruleId);
52 }
53
54 /**
55 * @see ValidationRuleSet::hasRules()
56 *
57 * @since 1.3.1
58 */
59 public function hasRules(): bool
60 {
61 return $this->validationRules->hasRules();
62 }
63
64 /**
65 * @see ValidationRuleSet::getRule()
66 *
67 * @since 1.0.0
68 */
69 public function getRule(string $ruleId): ValidationRule
70 {
71 return $this->validationRules->getRule($ruleId);
72 }
73
74 /**
75 * @see ValidationRuleSet::replaceRule()
76 *
77 * @since 1.3.1
78 */
79 public function replaceRule(string $ruleId, $rule): bool
80 {
81 return $this->validationRules->replaceRule($ruleId, $rule);
82 }
83
84 /**
85 * @see ValidationRuleSet::replaceOrAppendRule()
86 *
87 * @since 1.3.1
88 */
89 public function replaceOrAppendRule(string $ruleId, $rule): bool
90 {
91 return $this->validationRules->replaceOrAppendRule($ruleId, $rule);
92 }
93
94 /**
95 * @see ValidationRuleSet::replaceOrPrependRule()
96 *
97 * @since 1.3.1
98 */
99 public function replaceOrPrependRule(string $ruleId, $rule): bool
100 {
101 return $this->validationRules->replaceOrPrependRule($ruleId, $rule);
102 }
103
104 /**
105 * @see ValidationRuleSet::forgetRule()
106 *
107 * @since 1.0.0
108 */
109 public function forgetRule(string $ruleId): self
110 {
111 $this->validationRules->removeRuleWithId($ruleId);
112
113 return $this;
114 }
115
116 /**
117 * @since 1.0.0
118 */
119 public function getValidationRules(): ValidationRuleSet
120 {
121 return $this->validationRules;
122 }
123 }
124