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 $component_list; |
||
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 ComponentList $component_list |
||
61 | */ |
||
62 | public function __construct( ComponentList $component_list = null ) |
||
70 | |||
71 | /** |
||
72 | * Get the updated component values (validated, filtered or ignored). |
||
73 | * |
||
74 | * Loops through each component and acts according to its type: |
||
75 | * - Disableable components are ignored if they are disabled. |
||
76 | * - Validatable components are validated using their validation function. |
||
77 | * If the new value is invalid, the old value will be used. |
||
78 | * - Filterable components are filtered using their filter function. |
||
79 | * - Non-value components are skipped altogether. |
||
80 | * |
||
81 | * Each component is also set with its new value. |
||
82 | * |
||
83 | * @param array $new_instance The new component values array. |
||
84 | * @param array $old_instance The old component values array. |
||
85 | * |
||
86 | * @return array The updated values array. |
||
87 | */ |
||
88 | public function update( array $new_instance = array(), array $old_instance = array() ) |
||
102 | |||
103 | /** |
||
104 | * Reset all fields to their default values. |
||
105 | * |
||
106 | * @return array The updated values array. |
||
107 | */ |
||
108 | public function reset() |
||
114 | |||
115 | /** |
||
116 | * Reset the given list of components to their default values. |
||
117 | * |
||
118 | * @param array $components |
||
119 | * @return void |
||
120 | */ |
||
121 | public function reset_components( array $components ) |
||
129 | |||
130 | /** |
||
131 | * Reset the given component to its default value. |
||
132 | * |
||
133 | * @param AbstractComponent $component |
||
134 | * @return void |
||
135 | */ |
||
136 | public function reset_component( $component ) |
||
142 | |||
143 | /** |
||
144 | * Get the list of error messages for components that could not be validated. |
||
145 | * Structure: components_name => error_message |
||
146 | * |
||
147 | * @return string[] Array of error messages. |
||
148 | */ |
||
149 | public function get_errors() |
||
153 | |||
154 | /** |
||
155 | * Get all components. |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | public function get_component_list() |
||
163 | |||
164 | /** |
||
165 | * Update the component's value with the new value. |
||
166 | * NOTE: this function also updates the $final_instance |
||
167 | * array. |
||
168 | * |
||
169 | * @param ValueComponentInterface $component The component to validate. |
||
170 | */ |
||
171 | private function update_component( ValueComponentInterface $component ) |
||
187 | |||
188 | /** |
||
189 | * Check if the given component is disabled. |
||
190 | * |
||
191 | * @param UI\AbstractComponent $component |
||
192 | * @return boolean |
||
193 | */ |
||
194 | private function is_disabled( $component ) |
||
203 | |||
204 | /** |
||
205 | * Filter the component's value using its filter function (if applicable) |
||
206 | * |
||
207 | * @param UI\AbstractComponent $component |
||
208 | */ |
||
209 | private function filter( $component ) |
||
222 | |||
223 | /** |
||
224 | * Validate the component's value using its validation function. |
||
225 | * |
||
226 | * If the value is invalid, the old value is used, and an error message is |
||
227 | * saved into the errors array as component_name => error_message. |
||
228 | * |
||
229 | * @param UI\AbstractComponent $component The component to validate. |
||
230 | */ |
||
231 | private function validate( $component ) |
||
255 | |||
256 | /** |
||
257 | * Get the default values for all form components as an array of name => default_value |
||
258 | * |
||
259 | * @return array |
||
260 | */ |
||
261 | private function get_defaults() |
||
272 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..