1 | <?php |
||
37 | class AjaxValidationController extends ActionController |
||
38 | { |
||
39 | const ARGUMENT_FORM_CLASS_NAME = 'formClassName'; |
||
40 | const ARGUMENT_FORM_NAME = 'formName'; |
||
41 | const ARGUMENT_FORM = 'form'; |
||
42 | const ARGUMENT_FIELD_NAME = 'fieldName'; |
||
43 | const ARGUMENT_VALIDATOR_NAME = 'validatorName'; |
||
44 | |||
45 | const DEFAULT_ERROR_MESSAGE_KEY = 'default_error_message'; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | public static $requiredArguments = [ |
||
51 | self::ARGUMENT_FORM_CLASS_NAME, |
||
52 | self::ARGUMENT_FORM_NAME, |
||
53 | self::ARGUMENT_FORM, |
||
54 | self::ARGUMENT_FIELD_NAME, |
||
55 | self::ARGUMENT_VALIDATOR_NAME |
||
56 | ]; |
||
57 | |||
58 | /** |
||
59 | * @var JsonView |
||
60 | */ |
||
61 | protected $view; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $defaultViewObjectName = JsonView::class; |
||
67 | |||
68 | /** |
||
69 | * @var Request |
||
70 | */ |
||
71 | protected $request; |
||
72 | |||
73 | /** |
||
74 | * @var bool |
||
75 | */ |
||
76 | protected $protectedRequestMode = true; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | protected $formClassName; |
||
82 | |||
83 | /** |
||
84 | * @var string |
||
85 | */ |
||
86 | protected $formName; |
||
87 | |||
88 | /** |
||
89 | * @var array |
||
90 | */ |
||
91 | protected $form; |
||
92 | |||
93 | /** |
||
94 | * @var string |
||
95 | */ |
||
96 | protected $fieldName; |
||
97 | |||
98 | /** |
||
99 | * @var string |
||
100 | */ |
||
101 | protected $validatorName; |
||
102 | |||
103 | /** |
||
104 | * @var FormObject |
||
105 | */ |
||
106 | protected $formObject; |
||
107 | |||
108 | /** |
||
109 | * The only accepted method for the request is `POST`. |
||
110 | */ |
||
111 | public function initializeAction() |
||
117 | |||
118 | /** |
||
119 | * Main action that will render the validation result. |
||
120 | */ |
||
121 | public function runAction() |
||
130 | |||
131 | /** |
||
132 | * @param bool $flag |
||
133 | */ |
||
134 | public function setProtectedRequestMode($flag) |
||
138 | |||
139 | /** |
||
140 | * Will fetch the result and prevent any exception or external message to be |
||
141 | * displayed. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | protected function getProtectedRequestResult() |
||
170 | |||
171 | /** |
||
172 | * Will get the result of the validation for this Ajax request. |
||
173 | * |
||
174 | * If any error is found, an exception is thrown. |
||
175 | * |
||
176 | * @return array |
||
177 | */ |
||
178 | protected function getRequestResult() |
||
198 | |||
199 | /** |
||
200 | * Initializes all arguments for the request, and returns an array |
||
201 | * containing the missing arguments. |
||
202 | */ |
||
203 | protected function initializeArguments() |
||
224 | |||
225 | /** |
||
226 | * @return FormObject |
||
227 | */ |
||
228 | protected function getFormObject() |
||
235 | |||
236 | /** |
||
237 | * @throws InvalidConfigurationException |
||
238 | */ |
||
239 | protected function checkConfigurationValidationResult() |
||
250 | |||
251 | /** |
||
252 | * @return Validation |
||
253 | * @throws EntryNotFoundException |
||
254 | * @throws InvalidConfigurationException |
||
255 | */ |
||
256 | protected function getFieldValidation() |
||
279 | |||
280 | /** |
||
281 | * @param FormObject $formObject |
||
282 | * @return Form |
||
283 | * @throws EntryNotFoundException |
||
284 | */ |
||
285 | protected function getFormConfiguration(FormObject $formObject) |
||
298 | |||
299 | /** |
||
300 | * Will build and fill an object with a form sent value. |
||
301 | * |
||
302 | * @return FormInterface |
||
303 | */ |
||
304 | protected function buildObject() |
||
323 | |||
324 | /** |
||
325 | * Will convert the result of the function called by this class in a JSON |
||
326 | * string. |
||
327 | * |
||
328 | * @param Result $result |
||
329 | * @return array |
||
330 | */ |
||
331 | protected function convertResultToJson(Result $result) |
||
342 | |||
343 | /** |
||
344 | * @param string $name |
||
345 | * @return mixed |
||
346 | */ |
||
347 | protected function getArgument($name) |
||
351 | |||
352 | /** |
||
353 | * Will clean the string filled with form values sent with Ajax. |
||
354 | * |
||
355 | * @param array $values |
||
356 | * @return array |
||
357 | */ |
||
358 | protected function cleanValuesFromUrl($values) |
||
367 | } |
||
368 |