1 | <?php |
||
17 | class Validator extends \GUMP |
||
18 | { |
||
19 | /** |
||
20 | * Function to create and return previously created instance |
||
21 | * Renamed from get_instance() to follow $f3 design pattern |
||
22 | * as calling $this->get_instance() will ignore this class |
||
23 | * and get a GUMP instance instead if this method did not exist |
||
24 | * |
||
25 | * @return Validator |
||
26 | */ |
||
27 | public static function instance() |
||
35 | |||
36 | /** |
||
37 | * Perform data filtering against the provided ruleset. |
||
38 | * |
||
39 | * @param mixed $input |
||
40 | * @param array optinal $ruleset ot use class ruleset |
||
41 | * @return bool|array |
||
42 | */ |
||
43 | public function filter(array $input, array $ruleset = []) |
||
47 | |||
48 | /** |
||
49 | * Perform data validation against the provided ruleset. |
||
50 | * |
||
51 | * @param array $input |
||
52 | * @param array optinal $ruleset ot use class ruleset |
||
53 | * @return bool|array |
||
54 | */ |
||
55 | public function validate(array $input, array $ruleset = []) |
||
59 | |||
60 | /** |
||
61 | * A custom filter named "lower". |
||
62 | * |
||
63 | * The callback function receives two arguments: |
||
64 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
65 | * |
||
66 | * @param mixed $value |
||
67 | * @param mixed $param |
||
68 | * @return string |
||
69 | */ |
||
70 | public function filter_lower($value, $param = null): string |
||
74 | |||
75 | /** |
||
76 | * A custom filter named "upper". |
||
77 | * |
||
78 | * The callback function receives two arguments: |
||
79 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
80 | * |
||
81 | * @param mixed $value |
||
82 | * @param mixed $param |
||
83 | * @return string |
||
84 | */ |
||
85 | public function filter_upper($value, $param = null): string |
||
89 | |||
90 | /** |
||
91 | * Strip whitespaces from the beginning of a string |
||
92 | * |
||
93 | * The callback function receives two arguments: |
||
94 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
95 | * |
||
96 | * @param mixed $value |
||
97 | * @param mixed $param |
||
98 | * @return string |
||
99 | * @link https://fatfreeframework.com/utf-unicode-string-manager#ltrim |
||
100 | */ |
||
101 | public function filter_ltrim($value, $param = null): string |
||
105 | |||
106 | /** |
||
107 | * Strip whitespaces from the end of a string |
||
108 | * |
||
109 | * The callback function receives two arguments: |
||
110 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
111 | * |
||
112 | * @param mixed $value |
||
113 | * @param mixed $param |
||
114 | * @return string |
||
115 | * @link https://fatfreeframework.com/utf-unicode-string-manager#rtrim |
||
116 | */ |
||
117 | public function filter_rtrim($value, $param = null): string |
||
121 | |||
122 | /** |
||
123 | * Strip whitespaces from the beginning and end of a string |
||
124 | * |
||
125 | * The callback function receives two arguments: |
||
126 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
127 | * |
||
128 | * @param mixed $value |
||
129 | * @param mixed $param |
||
130 | * @return string |
||
131 | * @link https://fatfreeframework.com/utf-unicode-string-manager#trim |
||
132 | */ |
||
133 | public function filter_trim($value, $param = null): string |
||
137 | |||
138 | /** |
||
139 | * Convert code points to Unicode symbols |
||
140 | * |
||
141 | * The callback function receives two arguments: |
||
142 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
143 | * |
||
144 | * @param mixed $value |
||
145 | * @param mixed $param |
||
146 | * @return string |
||
147 | * @link https://fatfreeframework.com/utf-unicode-string-manager#translate |
||
148 | */ |
||
149 | public function filter_translate($value, $param = null): string |
||
153 | |||
154 | /** |
||
155 | * Translate emoji tokens to Unicode font-supported symbols |
||
156 | * |
||
157 | * The callback function receives two arguments: |
||
158 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
159 | * |
||
160 | * @param mixed $value |
||
161 | * @param mixed $param |
||
162 | * @return string |
||
163 | * @link https://fatfreeframework.com/utf-unicode-string-manager#emojify |
||
164 | */ |
||
165 | public function filter_emojify($value, $param = null): string |
||
169 | |||
170 | /** |
||
171 | * Convert input to a slug |
||
172 | * |
||
173 | * The callback function receives two arguments: |
||
174 | * The value to filter, and any parameters used in the filter rule. It should returned the filtered value. |
||
175 | * |
||
176 | * @param mixed $value |
||
177 | * @param mixed $param |
||
178 | * @return string |
||
179 | * @link https://fatfreeframework.com/utf-unicode-string-manager#emojify |
||
180 | */ |
||
181 | public function filter_slug($value, $param = null): string |
||
185 | |||
186 | /** |
||
187 | * Check whether the IP Address is Public |
||
188 | * |
||
189 | * Usage: '<index>' => 'valid_ip_public' |
||
190 | * |
||
191 | * @param string $field |
||
192 | * @param array $input |
||
193 | * @param null|array $param |
||
194 | * |
||
195 | * @return null|array |
||
196 | */ |
||
197 | public function validate_valid_ip_public(string $field, array $input, $param = null) |
||
211 | |||
212 | /** |
||
213 | * Check whether the IP Address is NOT Public |
||
214 | * |
||
215 | * Usage: '<index>' => 'valid_ip_not_public' |
||
216 | * |
||
217 | * @param string $field |
||
218 | * @param array $input |
||
219 | * @param null|array $param |
||
220 | * @return null|array |
||
221 | */ |
||
222 | public function validate_valid_ip_not_public(string $field, array $input, $param = null) |
||
236 | |||
237 | /** |
||
238 | * Check whether the IP Address is Reserved |
||
239 | * |
||
240 | * Usage: '<index>' => 'valid_ip_reserved' |
||
241 | * |
||
242 | * @param string $field |
||
243 | * @param array $input |
||
244 | * @param null|array $param |
||
245 | * @return null|array |
||
246 | */ |
||
247 | public function validate_valid_ip_reserved(string $field, array $input, $param = null) |
||
261 | |||
262 | /** |
||
263 | * Check whether the IP Address is Private or Reserved |
||
264 | * |
||
265 | * Usage: '<index>' => 'valid_ip_private' |
||
266 | * |
||
267 | * @param string $field |
||
268 | * @param array $input |
||
269 | * @param null|array $param |
||
270 | * @return null|array |
||
271 | */ |
||
272 | public function validate_valid_ip_private(string $field, array $input, $param = null) |
||
286 | |||
287 | } |
||
288 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.