PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.1
GiveWP – Donation Plugin and Fundraising Platform v4.1.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 / FormAPI / Section.php

Section.php in GiveWP – Donation Plugin and Fundraising Platform 4.1.1, at src/FormAPI/Section.php

92 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\FormAPI;
4
5 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
6
7 /**
8 * Class Options
9 *
10 * @package Give\Form\Theme
11 * @since 2.7.0
12 */
13 final class Section
14 {
15
16 /**
17 * Group id.
18 *
19 * @since 2.7.0
20 * @var string
21 */
22 public $id;
23
24 /**
25 * Name of group
26 *
27 * @since 2.7.0
28 * @var string
29 */
30 public $name;
31
32 /**
33 * Description og group.
34 *
35 * @since 2.7.0
36 * @var string
37 */
38 public $desc;
39
40 /**
41 * Array fo fields
42 *
43 * @since 2.7.0
44 * @var Fields[]
45 */
46 public $fields = [];
47
48 /**
49 * Convert array into Group class object.
50 *
51 * @since 2.7.0
52 *
53 * @param array $array
54 *
55 * @return static
56 */
57 public static function fromArray($array)
58 {
59 $group = new static();
60
61 $group->validate($array);
62
63 $group->id = $array['id'];
64 $group->name = $array['name'];
65 $group->desc = isset($array['desc']) ? $array['desc'] : null;
66
67 foreach ($array['fields'] as $field) {
68 $group->fields[] = Fields::fromArray($field);
69 }
70
71 return $group;
72 }
73
74 /**
75 * Validate group arguments
76 *
77 * @since 2.7.0
78 *
79 * @param $array
80 */
81 private function validate($array)
82 {
83 $required = ['id', 'name', 'fields'];
84
85 if (array_diff($required, array_keys($array))) {
86 throw new InvalidArgumentException(
87 __('To create a Group object, please provide id, name and fields.', 'give')
88 );
89 }
90 }
91 }
92