PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
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
89 lines 1.3 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 * @since 2.7.0
11 * @package Give\Form\Theme
12 */
13 class Section {
14
15 /**
16 * Group id.
17 *
18 * @since 2.7.0
19 * @var string
20 */
21 public $id;
22
23 /**
24 * Name of group
25 *
26 * @since 2.7.0
27 * @var string
28 */
29 public $name;
30
31
32 /**
33 * Description og group.
34 *
35 * @since 2.7.0
36 * @var string
37 */
38 public $desc;
39
40
41 /**
42 * Array fo fields
43 *
44 * @since 2.7.0
45 * @var Fields[]
46 */
47 public $fields = [];
48
49
50 /**
51 * Convert array into Group class object.
52 *
53 * @param array $array
54 *
55 * @since 2.7.0
56 *
57 * @return static
58 */
59 public static function fromArray( $array ) {
60 $group = new static();
61
62 $group->validate( $array );
63
64 $group->id = $array['id'];
65 $group->name = $array['name'];
66 $group->desc = isset( $array['desc'] ) ? $array['desc'] : null;
67
68 foreach ( $array['fields'] as $field ) {
69 $group->fields[] = Fields::fromArray( $field );
70 }
71
72 return $group;
73 }
74
75 /**
76 * Validate group arguments
77 *
78 * @since 2.7.0
79 * @param $array
80 */
81 private function validate( $array ) {
82 $required = [ 'id', 'name', 'fields' ];
83
84 if ( array_diff( $required, array_keys( $array ) ) ) {
85 throw new InvalidArgumentException( __( 'To create a Group object, please provide id, name and fields.', 'give' ) );
86 }
87 }
88 }
89