1 | <?php |
||
33 | class FormService implements SingletonInterface |
||
34 | { |
||
35 | |||
36 | /** |
||
37 | * @var FormInterface[] |
||
38 | */ |
||
39 | private static $formWithErrors = []; |
||
40 | |||
41 | /** |
||
42 | * Use this function to check if an action's required argument is missing. |
||
43 | * |
||
44 | * Basically, this can be used to prevent user from refreshing a page where |
||
45 | * a form has been submitted, but without sending the form again: the |
||
46 | * request calls the form submission controller action with an empty form |
||
47 | * object, which can result in a fatal error. You can use this function to |
||
48 | * prevent this kind of behaviour. Example: |
||
49 | * |
||
50 | * A controller has an action like: |
||
51 | * public function submitFormAction(MyForm $myForm) { ... } |
||
52 | * |
||
53 | * Add a new function: |
||
54 | * public function initializeSubmitFormAction() |
||
55 | * { |
||
56 | * FormUtility::onRequiredArgumentIsMissing( |
||
57 | * $this->arguments, |
||
58 | * $this->request, |
||
59 | * function($missingArgumentName) { |
||
60 | * $this->redirect('myIndex'); |
||
61 | * } |
||
62 | * ); |
||
63 | * } |
||
64 | * |
||
65 | * @param Arguments $arguments Arguments of the method arguments. |
||
66 | * @param Request $request Request. |
||
67 | * @param callable $callback Callback function which is called if a required argument is missing. |
||
68 | */ |
||
69 | public static function onRequiredArgumentIsMissing($arguments, $request, $callback) |
||
82 | |||
83 | /** |
||
84 | * If a form has been submitted with errors, use this function to get it |
||
85 | * back. |
||
86 | * This is useful because an action is forwarded if the submitted argument |
||
87 | * has errors. |
||
88 | * |
||
89 | * @param string $formClassName The class name of the form. |
||
90 | * @return FormInterface|null |
||
91 | */ |
||
92 | public static function getFormWithErrors($formClassName) |
||
98 | |||
99 | /** |
||
100 | * If a form validation has failed, this function is used to save it for |
||
101 | * further usage. |
||
102 | * |
||
103 | * @param FormInterface $form |
||
104 | * @internal |
||
105 | */ |
||
106 | public static function addFormWithErrors(FormInterface $form) |
||
110 | } |
||
111 |