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; |
||
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() ) |
||
74 | |||
75 | /** |
||
76 | * Get the updated component values (validated, filtered or ignored). |
||
77 | * |
||
78 | * Loops through each component and acts according to its type: |
||
79 | * - Disableable components are ignored if they are disabled. |
||
80 | * - Validatable components are validated using their validation function. |
||
81 | * If the new value is invalid, the old value will be used. |
||
82 | * - Filterable components are filtered using their filter function. |
||
83 | * - Non-value components are skipped altogether. |
||
84 | * |
||
85 | * Each component is also set with its new value. |
||
86 | * |
||
87 | * @param array $new_instance The new component values array. |
||
88 | * @param array $old_instance The old component values array. |
||
89 | * |
||
90 | * @return array The updated values array. |
||
91 | */ |
||
92 | public function update( array $new_instance, array $old_instance = array() ) |
||
109 | |||
110 | /** |
||
111 | * Reset all fields to their default values. |
||
112 | * |
||
113 | * @return array The updated values array. |
||
114 | */ |
||
115 | public function reset() |
||
124 | |||
125 | /** |
||
126 | * Get the list of error messages for components that could not be validated. |
||
127 | * Structure: components_name => error_message |
||
128 | * |
||
129 | * @return string[] Array of error messages. |
||
130 | */ |
||
131 | public function get_errors() |
||
135 | |||
136 | /** |
||
137 | * Get a component by its name. |
||
138 | * |
||
139 | * @param string $name |
||
140 | * @return UI\AbstractComponent |
||
141 | */ |
||
142 | public function get_component( $name ) |
||
146 | |||
147 | /** |
||
148 | * Get all components. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function get_components() |
||
156 | |||
157 | /** |
||
158 | * Update the component's value with the new value. |
||
159 | * NOTE: this function also updates the $final_instance |
||
160 | * array. |
||
161 | * |
||
162 | * @param ValueComponentInterface $component The component to validate. |
||
163 | */ |
||
164 | private function update_component( ValueComponentInterface $component ) |
||
180 | |||
181 | /** |
||
182 | * Check if the given component is disabled. |
||
183 | * |
||
184 | * @param UI\AbstractComponent $component |
||
185 | * @return boolean |
||
186 | */ |
||
187 | private function is_disabled( $component ) |
||
196 | |||
197 | /** |
||
198 | * Filter the component's value using its filter function (if applicable) |
||
199 | * |
||
200 | * @param UI\AbstractComponent $component |
||
201 | */ |
||
202 | private function filter( $component ) |
||
215 | |||
216 | /** |
||
217 | * Validate the component's value using its validation function. |
||
218 | * |
||
219 | * If the value is invalid, the old value is used, and an error message is |
||
220 | * saved into the errors array as component_name => error_message. |
||
221 | * |
||
222 | * @param UI\AbstractComponent $component The component to validate. |
||
223 | */ |
||
224 | private function validate( $component ) |
||
248 | |||
249 | /** |
||
250 | * Get the default values for all form components as an array of name => default_value |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | private function get_defaults() |
||
265 | } |
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.