1 | <?php |
||
37 | class FormController extends ActionController |
||
38 | { |
||
39 | /** |
||
40 | * @var ControllerProcessor |
||
41 | */ |
||
42 | protected $processor; |
||
43 | |||
44 | /** |
||
45 | * Main action used to dispatch the request properly, depending on FormZ |
||
46 | * configuration. |
||
47 | * |
||
48 | * The request is based on the previously called controller action, and is |
||
49 | * used to list which forms are handled (every argument of the action method |
||
50 | * that implements the interface `FormInterface`). |
||
51 | * |
||
52 | * Middlewares will be called for each form argument, and may modify the |
||
53 | * request, which is then dispatched again with modified data. |
||
54 | * |
||
55 | * @throws Exception |
||
56 | */ |
||
57 | public function processFormAction() |
||
58 | { |
||
59 | $exception = null; |
||
60 | |||
61 | try { |
||
62 | $this->invokeMiddlewares(); |
||
63 | $this->manageRequestResult(); |
||
64 | } catch (Exception $exception) { |
||
|
|||
65 | } catch (Throwable $exception) { |
||
66 | } |
||
67 | |||
68 | $this->persistForms(); |
||
69 | |||
70 | if ($exception) { |
||
71 | if ($exception instanceof StopPropagationException) { |
||
72 | if ($exception instanceof RedirectException) { |
||
73 | $this->redirectFromException($exception); |
||
74 | } elseif (false === $exception instanceof ForwardException) { |
||
75 | $this->resetSubstepsLevel(); |
||
76 | $this->forwardToReferrer(); |
||
77 | } |
||
78 | } elseif ($this->processor->hasExceptionCallback() |
||
79 | && false === $exception instanceof StopActionException |
||
80 | ) { |
||
81 | call_user_func($this->processor->getExceptionCallback(), $exception); |
||
82 | } else { |
||
83 | throw $exception; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | $this->continueRequest(); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param FormObject $formObject |
||
92 | */ |
||
93 | public function formObjectErrorAction(FormObject $formObject) |
||
97 | |||
98 | /** |
||
99 | * Will fetch every form argument for this request, and dispatch every |
||
100 | * middleware that was registered in its TypoScript configuration. |
||
101 | */ |
||
102 | protected function invokeMiddlewares() |
||
111 | |||
112 | /** |
||
113 | * @todo |
||
114 | */ |
||
115 | protected function resetSubstepsLevel() |
||
122 | |||
123 | /** |
||
124 | * Will check if the request result contains error; if errors are found, the |
||
125 | * request is forwarded to the referring request, with the arguments of the |
||
126 | * current request. |
||
127 | */ |
||
128 | protected function manageRequestResult() |
||
137 | |||
138 | /** |
||
139 | * Loops on every form of this request, and persists each one. |
||
140 | */ |
||
141 | protected function persistForms() |
||
157 | |||
158 | /** |
||
159 | * Forwards the request to the original request that led to this controller. |
||
160 | * |
||
161 | * @throws StopActionException |
||
162 | */ |
||
163 | protected function continueRequest() |
||
177 | |||
178 | /** |
||
179 | * Forwards to the referrer request. It will also fill the arguments of the |
||
180 | * action with the ones from the source request. |
||
181 | * |
||
182 | * @throws StopActionException |
||
183 | */ |
||
184 | protected function forwardToReferrer() |
||
206 | |||
207 | /** |
||
208 | * @param RedirectException $redirectException |
||
209 | */ |
||
210 | protected function redirectFromException(RedirectException $redirectException) |
||
224 | |||
225 | /** |
||
226 | * @param ControllerProcessor $processor |
||
227 | */ |
||
228 | public function injectProcessor(ControllerProcessor $processor) |
||
232 | } |
||
233 |