1 | <?php |
||
8 | class FieldManager |
||
9 | { |
||
10 | /** |
||
11 | * Array of fields |
||
12 | * @var array |
||
13 | */ |
||
14 | private $fields; |
||
15 | |||
16 | /** |
||
17 | * @param array $fields optional default array of field configs |
||
18 | */ |
||
19 | public function __construct($fields = []) |
||
23 | |||
24 | /** |
||
25 | * @return NamedBuilder[] field configs |
||
26 | */ |
||
27 | public function getFields() |
||
31 | |||
32 | /** |
||
33 | * Return int of fields |
||
34 | * @return int field count |
||
35 | */ |
||
36 | public function getCount() |
||
40 | |||
41 | /** |
||
42 | * Add field to end of array |
||
43 | * @param NamedBuilder $field Field array config or Builder |
||
44 | * @return void |
||
45 | */ |
||
46 | public function pushField($field) |
||
50 | |||
51 | /** |
||
52 | * Remove last field from end of array |
||
53 | * @throws \OutOfRangeException if array is empty |
||
54 | * @return NamedBuilder Field array config or Builder |
||
55 | */ |
||
56 | public function popField() |
||
65 | |||
66 | /** |
||
67 | * Insert of field at a specific index |
||
68 | * @param NamedBuilder $fields a single field or an array of fields |
||
69 | * @param int $index insertion point |
||
70 | * @return void |
||
71 | */ |
||
72 | public function insertFields($fields, $index) |
||
90 | |||
91 | /** |
||
92 | * Remove a field at a specific index |
||
93 | * @param int $index |
||
94 | * @return array removed field |
||
95 | */ |
||
96 | private function removeFieldAtIndex($index) |
||
100 | |||
101 | /** |
||
102 | * Remove a speicifc field by name |
||
103 | * @param string $name name of the field |
||
104 | * @return void |
||
105 | */ |
||
106 | public function removeField($name) |
||
111 | |||
112 | /** |
||
113 | * Replace a field with a single field or array of fields |
||
114 | * @param string $name name of field to replace |
||
115 | * @param NamedBuilder $field single or array of fields |
||
116 | * @return void |
||
117 | */ |
||
118 | public function replaceField($name, $field) |
||
124 | |||
125 | /** |
||
126 | * Check to see if a field name already exists |
||
127 | * @param string $name field name |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function fieldNameExists($name) |
||
140 | |||
141 | /** |
||
142 | * Return a field by name |
||
143 | * @param string $name field name |
||
144 | * @return FieldBuilder |
||
145 | */ |
||
146 | public function getField($name) |
||
150 | |||
151 | /** |
||
152 | * Modify the configuration of a field |
||
153 | * @param string $name field name |
||
154 | * @param array $modifications field configuration |
||
155 | * @return void |
||
156 | */ |
||
157 | public function modifyField($name, $modifications) |
||
162 | |||
163 | /** |
||
164 | * Validate a field |
||
165 | * @param NamedBuilder $field |
||
166 | * @return bool |
||
167 | */ |
||
168 | private function validateField($field) |
||
172 | |||
173 | /** |
||
174 | * Validates that a field's name doesn't already exist |
||
175 | * @param NamedBuilder $field |
||
176 | * @throws FieldNameCollisionException when the name already exists |
||
177 | * @return bool |
||
178 | */ |
||
179 | private function validateFieldName($field) |
||
188 | |||
189 | /** |
||
190 | * Return the index in the $this->fields array looked up by the field's name |
||
191 | * @param string $name Field Name |
||
192 | * @throws FieldNotFoundException if the field name doesn't exist |
||
193 | * @return int Field Index |
||
194 | */ |
||
195 | public function getFieldIndex($name) |
||
205 | } |
||
206 |