PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Settings / Validator / Validate.php

Validate.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.14, at app/Services/Settings/Validator/Validate.php

58 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 FluentForm\App\Services\Settings\Validator;
4
5 use FluentForm\Framework\Validator\Validator;
6 use FluentForm\Framework\Validator\ValidationException;
7
8 abstract class Validate
9 {
10 /**
11 * Validates confirmations settings data.
12 *
13 * @param array $data
14 *
15 * @return bool
16 */
17 public static function validate($data = [])
18 {
19 // Prepare the validation rules & messages.
20 [$rules, $messages] = static::validations();
21
22 // Make validator instance.
23 $validator = wpFluentForm('validator')->make($data, $rules, $messages);
24
25 // Add conditional validations if there's any.
26 $validator = static::conditionalValidations($validator);
27
28 // Validate and process response.
29 if ($validator->validate()->fails()) {
30 throw new ValidationException('Unprocessable Entity!', 422, null, $validator->errors()); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
31 }
32
33 return true;
34 }
35
36 /**
37 * Produce the necessary validation rules and corresponding messages
38 *
39 * @return array
40 */
41 public static function validations()
42 {
43 return [[], []];
44 }
45
46 /**
47 * Add conditional validations to the validator.
48 *
49 * @param \FluentForm\Framework\Validator\Validator $validator
50 *
51 * @return \FluentForm\Framework\Validator\Validator
52 */
53 public static function conditionalValidations(Validator $validator)
54 {
55 return $validator;
56 }
57 }
58