1 | <?php |
||
50 | class AjaxValidationController extends ActionController |
||
51 | { |
||
52 | const DEFAULT_ERROR_MESSAGE_KEY = 'default_error_message'; |
||
53 | const MAPPING_ERROR = 'MappingError'; |
||
54 | |||
55 | /** |
||
56 | * @var Request |
||
57 | */ |
||
58 | protected $request; |
||
59 | |||
60 | /** |
||
61 | * @var Response |
||
62 | */ |
||
63 | protected $response; |
||
64 | |||
65 | /** |
||
66 | * @var bool |
||
67 | */ |
||
68 | protected $protectedRequestMode = true; |
||
69 | |||
70 | /** |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $formClassName; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $formName; |
||
79 | |||
80 | /** |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $fieldName; |
||
84 | |||
85 | /** |
||
86 | * @var string |
||
87 | */ |
||
88 | protected $validatorName; |
||
89 | |||
90 | /** |
||
91 | * @var FormInterface |
||
92 | */ |
||
93 | protected $form; |
||
94 | |||
95 | /** |
||
96 | * @var FormObject |
||
97 | */ |
||
98 | protected $formObject; |
||
99 | |||
100 | /** |
||
101 | * @var AjaxResult |
||
102 | */ |
||
103 | protected $result; |
||
104 | |||
105 | /** |
||
106 | * @var Validator |
||
107 | */ |
||
108 | protected $validation; |
||
109 | |||
110 | /** |
||
111 | * The only accepted method for the request is `POST`. |
||
112 | */ |
||
113 | public function initializeAction() |
||
119 | |||
120 | /** |
||
121 | * Will process the request, but also prevent any external message to be |
||
122 | * displayed, and catch any exception that could occur during the |
||
123 | * validation. |
||
124 | * |
||
125 | * @param RequestInterface $request |
||
126 | * @param ResponseInterface $response |
||
127 | * @throws Exception |
||
128 | */ |
||
129 | public function processRequest(RequestInterface $request, ResponseInterface $response) |
||
156 | |||
157 | /** |
||
158 | * Will get the default error message from the form configuartion |
||
159 | */ |
||
160 | protected function getDefaultErrorMessage() |
||
168 | |||
169 | /** |
||
170 | * Will take care of adding a new argument to the request, based on the form |
||
171 | * name and the form class name found in the request arguments. |
||
172 | */ |
||
173 | protected function initializeActionMethodValidators() |
||
203 | |||
204 | /** |
||
205 | * Main action that will process the field validation. |
||
206 | * |
||
207 | * @param string $name |
||
208 | * @param string $className |
||
209 | * @param string $fieldName |
||
210 | * @param string $validatorName |
||
211 | * @param string $formzData |
||
212 | */ |
||
213 | public function runAction($name, $className, $fieldName, $validatorName, $formzData) |
||
245 | |||
246 | /** |
||
247 | * If an error occurs, that must be because the mapping of the arguments |
||
248 | * failed somehow. Therefore we override the default behaviour (forward to |
||
249 | * referring request) and we throw an exception instead. |
||
250 | * |
||
251 | * @throws InvalidArgumentValueException |
||
252 | */ |
||
253 | public function errorAction() |
||
263 | |||
264 | /** |
||
265 | * Will call all middlewares of the form. |
||
266 | * |
||
267 | * Note that the field validation scope is used, meaning some middlewares |
||
268 | * wont be called. |
||
269 | * |
||
270 | * @see \Romm\Formz\Middleware\Scope\FieldValidationScope |
||
271 | */ |
||
272 | protected function invokeMiddlewares() |
||
299 | |||
300 | /** |
||
301 | * Will fetch the settings of the content object that was used to render the |
||
302 | * form calling this controller. |
||
303 | * |
||
304 | * @return array |
||
305 | */ |
||
306 | protected function getContentObjectSettings() |
||
317 | |||
318 | /** |
||
319 | * @return Validator |
||
320 | * @throws EntryNotFoundException |
||
321 | * @throws InvalidConfigurationException |
||
322 | */ |
||
323 | protected function getFieldValidation() |
||
351 | |||
352 | /** |
||
353 | * Fetches errors/warnings/notices in the result, and put them in the JSON |
||
354 | * response. |
||
355 | */ |
||
356 | protected function injectResultInResponse() |
||
376 | |||
377 | /** |
||
378 | * @param array $result |
||
379 | */ |
||
380 | protected function setUpResponseResult(array $result) |
||
387 | |||
388 | /** |
||
389 | * @param FormzMessageInterface[] $messages |
||
390 | * @return array |
||
391 | */ |
||
392 | protected function formatMessages(array $messages) |
||
402 | |||
403 | /** |
||
404 | * Wrapper for unit tests. |
||
405 | * |
||
406 | * @param RequestInterface $request |
||
407 | * @param ResponseInterface $response |
||
408 | */ |
||
409 | protected function processRequestParent(RequestInterface $request, ResponseInterface $response) |
||
413 | |||
414 | /** |
||
415 | * Wrapper for unit tests. |
||
416 | */ |
||
417 | protected function initializeActionMethodValidatorsParent() |
||
421 | |||
422 | /** |
||
423 | * Used in unit testing. |
||
424 | * |
||
425 | * @param bool $flag |
||
426 | */ |
||
427 | public function setProtectedRequestMode($flag) |
||
431 | |||
432 | /** |
||
433 | * @param Exception $exception |
||
434 | * @return string |
||
435 | */ |
||
436 | protected function getDebugMessageForException(Exception $exception) |
||
440 | |||
441 | /** |
||
442 | * @return FormInterface |
||
443 | * @throws MissingArgumentException |
||
444 | */ |
||
445 | protected function getForm() |
||
452 | |||
453 | /** |
||
454 | * @return FormObject |
||
455 | */ |
||
456 | protected function getFormObject() |
||
460 | |||
461 | /** |
||
462 | * Wrapper for unit tests. |
||
463 | * |
||
464 | * @return Request |
||
465 | */ |
||
466 | protected function getRequest() |
||
470 | } |
||
471 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.