1 | <?php |
||
11 | class Form |
||
12 | { |
||
13 | /** |
||
14 | * The list of AbstractComponent type objects to be updated. |
||
15 | * |
||
16 | * @var AbstractComponent[] objects array. |
||
17 | */ |
||
18 | private $components = array(); |
||
19 | |||
20 | /** |
||
21 | * The old component values array. These values are used if the new values |
||
22 | * are invalid. |
||
23 | * Structure: component_name => component_value |
||
24 | * |
||
25 | * @var array Old values array. |
||
26 | */ |
||
27 | private $old_instance; |
||
28 | |||
29 | /** |
||
30 | * The new component values array. |
||
31 | * Structure: component_name => component_value |
||
32 | * |
||
33 | * @var array New values array. |
||
34 | */ |
||
35 | private $new_instance; |
||
36 | |||
37 | /** |
||
38 | * The final values array, after filtering and validation. |
||
39 | * This is returned by the update function. |
||
40 | * Structure: component_name => component_value |
||
41 | * |
||
42 | * @var array Final values array. |
||
43 | */ |
||
44 | private $final_instance = array(); |
||
45 | |||
46 | /** |
||
47 | * Array of names of components that were invalid, and the error message |
||
48 | * recieved. |
||
49 | * Structure: component_name => error_message |
||
50 | * |
||
51 | * @var string[] Array of error messages. |
||
52 | */ |
||
53 | private $errors = array(); |
||
54 | |||
55 | /** |
||
56 | * When instantiating a form, a list of component arguments arrays must be |
||
57 | * provided. Each arguments array must have a 'type' argument, in addition |
||
58 | * to the component's original arguments. |
||
59 | * |
||
60 | * @param array $components An array of arrays of component arguments |
||
61 | */ |
||
62 | public function __construct( array $components = array() ) |
||
66 | |||
67 | /** |
||
68 | * Get the updated component values (validated, filtered or ignored). |
||
69 | * |
||
70 | * Loops through each component and acts according to its type: |
||
71 | * - Disableable components are ignored if they are disabled. |
||
72 | * - Validatable components are validated using their validation function. |
||
73 | * If the new value is invalid, the old value will be used. |
||
74 | * - Filterable components are filtered using their filter function. |
||
75 | * - Non-value components are skipped altogether. |
||
76 | * |
||
77 | * Each component is also set with its new value. |
||
78 | * |
||
79 | * @param array $new_instance The new component values array. |
||
80 | * @param array $old_instance The old component values array. |
||
81 | * |
||
82 | * @return array The updated values array. |
||
83 | */ |
||
84 | public function update( array $new_instance = array(), array $old_instance = array() ) |
||
101 | |||
102 | /** |
||
103 | * Reset all fields to their default values. |
||
104 | * |
||
105 | * @return array The updated values array. |
||
106 | */ |
||
107 | public function reset() |
||
116 | |||
117 | /** |
||
118 | * Get the list of error messages for components that could not be validated. |
||
119 | * Structure: components_name => error_message |
||
120 | * |
||
121 | * @return string[] Array of error messages. |
||
122 | */ |
||
123 | public function get_errors() |
||
127 | |||
128 | /** |
||
129 | * Add a component to the form. |
||
130 | * |
||
131 | * @param array $args The component arguments |
||
132 | * @throws \RuntimeException If a component with the same name has already been registered |
||
133 | */ |
||
134 | public function add_component( array $args ) |
||
143 | |||
144 | /** |
||
145 | * Add multiple components to the form. |
||
146 | * |
||
147 | * @param array $components |
||
148 | */ |
||
149 | public function add_components( array $components ) |
||
156 | |||
157 | /** |
||
158 | * Get a component by its name. |
||
159 | * |
||
160 | * @param string $name |
||
161 | * @return UI\AbstractComponent |
||
162 | */ |
||
163 | public function get_component( $name ) |
||
167 | |||
168 | /** |
||
169 | * Get all components. |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | public function get_components() |
||
177 | |||
178 | /** |
||
179 | * Update the component's value with the new value. |
||
180 | * NOTE: this function also updates the $final_instance |
||
181 | * array. |
||
182 | * |
||
183 | * @param ValueComponentInterface $component The component to validate. |
||
184 | */ |
||
185 | private function update_component( ValueComponentInterface $component ) |
||
201 | |||
202 | /** |
||
203 | * Check if the given component is disabled. |
||
204 | * |
||
205 | * @param UI\AbstractComponent $component |
||
206 | * @return boolean |
||
207 | */ |
||
208 | private function is_disabled( $component ) |
||
217 | |||
218 | /** |
||
219 | * Filter the component's value using its filter function (if applicable) |
||
220 | * |
||
221 | * @param UI\AbstractComponent $component |
||
222 | */ |
||
223 | private function filter( $component ) |
||
236 | |||
237 | /** |
||
238 | * Validate the component's value using its validation function. |
||
239 | * |
||
240 | * If the value is invalid, the old value is used, and an error message is |
||
241 | * saved into the errors array as component_name => error_message. |
||
242 | * |
||
243 | * @param UI\AbstractComponent $component The component to validate. |
||
244 | */ |
||
245 | private function validate( $component ) |
||
269 | |||
270 | /** |
||
271 | * Get the default values for all form components as an array of name => default_value |
||
272 | * |
||
273 | * @return array |
||
274 | */ |
||
275 | private function get_defaults() |
||
286 | } |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.