PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.2
GiveWP – Donation Plugin and Fundraising Platform v4.15.2
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 / Actions / CreateValidatorFromFormFields.php
CreateValidatorFromFormFields.php
38 lines 869 B
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\Framework\FieldsAPI\Actions;
6
7 use Give\Framework\FieldsAPI\Field;
8 use Give\Vendors\StellarWP\Validation\Validator;
9
10 class CreateValidatorFromFormFields
11 {
12 /**
13 * @since 3.0.0
14 *
15 * @param Field[] $formFields
16 * @param array $values
17 *
18 * @return Validator
19 */
20 public function __invoke(array $formFields, array $values): Validator
21 {
22 $labels = [];
23 $rules = [];
24
25 foreach ($formFields as $field) {
26 $rules[$field->getName()] = (new UpdateValidationRulesWithOptionalAsDefault())(
27 $field->getValidationRules()
28 );
29
30 if (method_exists($field, 'getLabel')) {
31 $labels[$field->getName()] = $field->getLabel();
32 }
33 }
34
35 return new Validator($rules, $values, $labels);
36 }
37 }
38