1 | <?php |
||
30 | class JavaScriptAssetHandlerConnector |
||
31 | { |
||
32 | /** |
||
33 | * List of JavaScript files which will be included whenever this view helper |
||
34 | * is used. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | private $javaScriptFiles = [ |
||
39 | 'Formz.Main.js', |
||
40 | 'Formz.Misc.js', |
||
41 | 'Formz.EventsManager.js', |
||
42 | 'Formz.Result.js', |
||
43 | 'Formz.Localization.js', |
||
44 | 'Form/Formz.Form.js', |
||
45 | 'Form/Formz.Form.SubmissionService.js', |
||
46 | 'Field/Formz.Field.js', |
||
47 | 'Field/Formz.Field.DataAttributesService.js', |
||
48 | 'Field/Formz.Field.ValidationService.js', |
||
49 | 'Conditions/Formz.Condition.js', |
||
50 | 'Validators/Formz.Validation.js', |
||
51 | 'Validators/Formz.Validator.Ajax.js' |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @var AssetHandlerConnectorManager |
||
56 | */ |
||
57 | private $assetHandlerConnectorManager; |
||
58 | |||
59 | /** |
||
60 | * @param AssetHandlerConnectorManager $assetHandlerConnectorManager |
||
61 | */ |
||
62 | public function __construct(AssetHandlerConnectorManager $assetHandlerConnectorManager) |
||
66 | |||
67 | /** |
||
68 | * Will include all default JavaScript files declared in the property |
||
69 | * `$javaScriptFiles` of this class, as well as the main Formz |
||
70 | * configuration. |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function includeDefaultJavaScriptFiles() |
||
90 | |||
91 | /** |
||
92 | * This function will handle the JavaScript language files. |
||
93 | * |
||
94 | * A file will be created for the current language (there can be as many |
||
95 | * files as languages), containing the translations handling for JavaScript. |
||
96 | * If the file already exists, it is directly included. |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function includeLanguageJavaScriptFiles() |
||
119 | |||
120 | /** |
||
121 | * Includes Formz configuration JavaScript declaration. If the file exists, |
||
122 | * it is directly included, otherwise the JavaScript code is calculated, |
||
123 | * then put in the cache file. |
||
124 | * |
||
125 | * @return $this |
||
126 | */ |
||
127 | public function generateAndIncludeFormzConfigurationJavaScript() |
||
145 | |||
146 | /** |
||
147 | * Will include the generated JavaScript, from multiple asset handlers |
||
148 | * sources. |
||
149 | * |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function generateAndIncludeJavaScript() |
||
184 | |||
185 | /** |
||
186 | * Here we generate the JavaScript code containing the submitted values, and |
||
187 | * the existing errors, which is dynamically created at each request. |
||
188 | * |
||
189 | * The code is then injected as inline code in the DOM. |
||
190 | * |
||
191 | * @return $this |
||
192 | */ |
||
193 | public function generateAndIncludeInlineJavaScript() |
||
218 | |||
219 | /** |
||
220 | * Will include all new JavaScript files given, by checking that every given |
||
221 | * file was not already included. |
||
222 | * |
||
223 | * @return $this |
||
224 | */ |
||
225 | public function includeJavaScriptValidationAndConditionFiles() |
||
244 | |||
245 | /** |
||
246 | * Returns the list of JavaScript files which are used for the current form |
||
247 | * object. |
||
248 | * |
||
249 | * @return array |
||
250 | */ |
||
251 | protected function getJavaScriptFiles() |
||
266 | |||
267 | /** |
||
268 | * @return string |
||
269 | */ |
||
270 | protected function getAjaxUrl() |
||
282 | |||
283 | /** |
||
284 | * @return string |
||
285 | */ |
||
286 | protected function getDebugActivationCode() |
||
290 | |||
291 | /** |
||
292 | * @param FormObject $formObject |
||
293 | * @return ConditionProcessor |
||
294 | */ |
||
295 | protected function getConditionProcessor(FormObject $formObject) |
||
300 | |||
301 | /** |
||
302 | * @return FormzConfigurationJavaScriptAssetHandler|AbstractAssetHandler |
||
303 | */ |
||
304 | protected function getFormzConfigurationJavaScriptAssetHandler() |
||
310 | |||
311 | /** |
||
312 | * @return FormInitializationJavaScriptAssetHandler|AbstractAssetHandler |
||
313 | */ |
||
314 | protected function getFormInitializationJavaScriptAssetHandler() |
||
320 | |||
321 | /** |
||
322 | * @return FieldsValidationJavaScriptAssetHandler|AbstractAssetHandler |
||
323 | */ |
||
324 | protected function getFieldsValidationJavaScriptAssetHandler() |
||
330 | |||
331 | /** |
||
332 | * @return FieldsActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
333 | */ |
||
334 | protected function getFieldsActivationJavaScriptAssetHandler() |
||
340 | |||
341 | /** |
||
342 | * @return FieldsValidationActivationJavaScriptAssetHandler|AbstractAssetHandler |
||
343 | */ |
||
344 | protected function getFieldsValidationActivationJavaScriptAssetHandler() |
||
350 | |||
351 | /** |
||
352 | * @return FormRequestDataJavaScriptAssetHandler|AbstractAssetHandler |
||
353 | */ |
||
354 | protected function getFormRequestDataJavaScriptAssetHandler() |
||
360 | |||
361 | /** |
||
362 | * @return FormzLocalizationJavaScriptAssetHandler|AbstractAssetHandler |
||
363 | */ |
||
364 | protected function getFormzLocalizationJavaScriptAssetHandler() |
||
370 | } |
||
371 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: