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() |
||
112 | { |
||
113 | if ($this->request->getMethod() !== 'POST') { |
||
114 | $this->throwStatus(400); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | public function getView() |
||
122 | |||
123 | /** |
||
124 | * Main action that will render the validation result. |
||
125 | */ |
||
126 | public function runAction() |
||
135 | |||
136 | /** |
||
137 | * @param bool $flag |
||
138 | */ |
||
139 | public function setProtectedRequestMode($flag) |
||
143 | |||
144 | /** |
||
145 | * Will fetch the result and prevent any exception or external message to be |
||
146 | * displayed. |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | protected function getProtectedRequestResult() |
||
175 | |||
176 | /** |
||
177 | * Will get the result of the validation for this Ajax request. |
||
178 | * |
||
179 | * If any error is found, an exception is thrown. |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | protected function getRequestResult() |
||
203 | |||
204 | /** |
||
205 | * Initializes all arguments for the request, and returns an array |
||
206 | * containing the missing arguments. |
||
207 | */ |
||
208 | protected function initializeArguments() |
||
229 | |||
230 | /** |
||
231 | * @return FormObject |
||
232 | */ |
||
233 | protected function getFormObject() |
||
240 | |||
241 | /** |
||
242 | * @throws InvalidConfigurationException |
||
243 | */ |
||
244 | protected function checkConfigurationValidationResult() |
||
255 | |||
256 | /** |
||
257 | * @return Validation |
||
258 | * @throws EntryNotFoundException |
||
259 | * @throws InvalidConfigurationException |
||
260 | */ |
||
261 | protected function getFieldValidation() |
||
284 | |||
285 | /** |
||
286 | * @param FormObject $formObject |
||
287 | * @return Form |
||
288 | * @throws EntryNotFoundException |
||
289 | */ |
||
290 | protected function getFormConfiguration(FormObject $formObject) |
||
303 | |||
304 | /** |
||
305 | * Will build and fill an object with a form sent value. |
||
306 | * |
||
307 | * @return FormInterface |
||
308 | */ |
||
309 | protected function buildFormObject() |
||
315 | |||
316 | /** |
||
317 | * Will convert the result of the function called by this class in a JSON |
||
318 | * string. |
||
319 | * |
||
320 | * @param Result $result |
||
321 | * @return array |
||
322 | */ |
||
323 | protected function convertResultToJson(Result $result) |
||
334 | |||
335 | /** |
||
336 | * @param \Exception $exception |
||
337 | * @return string |
||
338 | */ |
||
339 | protected function getDebugMessageForException(\Exception $exception) |
||
343 | |||
344 | /** |
||
345 | * @param string $name |
||
346 | * @return mixed |
||
347 | */ |
||
348 | protected function getArgument($name) |
||
352 | |||
353 | /** |
||
354 | * Will clean the string filled with form values sent with Ajax. |
||
355 | * |
||
356 | * @param array $values |
||
357 | * @return array |
||
358 | */ |
||
359 | protected function cleanValuesFromUrl($values) |
||
368 | |||
369 | /** |
||
370 | * @return PropertyMapper |
||
371 | */ |
||
372 | protected function getPropertyMapper() |
||
379 | } |
||
380 |