1 | <?php |
||
33 | class StepMiddlewareService implements SingletonInterface |
||
34 | { |
||
35 | use SelfInstantiateTrait; |
||
36 | |||
37 | /** |
||
38 | * @var FormObject |
||
39 | */ |
||
40 | protected $formObject; |
||
41 | |||
42 | /** |
||
43 | * @var FormStepPersistence |
||
44 | */ |
||
45 | protected $formStepPersistence; |
||
46 | |||
47 | /** |
||
48 | * @param FormObject $formObject |
||
49 | */ |
||
50 | public function reset(FormObject $formObject) |
||
51 | { |
||
52 | $this->formObject = $formObject; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Marks the given step as validated: no errors were found during validation |
||
57 | * with the given values array. |
||
58 | * |
||
59 | * @param Step $step |
||
60 | * @param array $formValues |
||
61 | */ |
||
62 | public function markStepAsValidated(Step $step, array $formValues) |
||
63 | { |
||
64 | $this->getStepPersistence()->markStepAsValidated($step); |
||
65 | $this->getStepPersistence()->addStepFormValues($step, $formValues); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param array $validatedFields |
||
70 | */ |
||
71 | public function addValidatedFields(array $validatedFields) |
||
72 | { |
||
73 | $this->getStepPersistence()->addValidatedFields($validatedFields); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Checks that the previous step has already been validated, meaning the |
||
78 | * user has the right to stand in the given step. |
||
79 | * |
||
80 | * @param Step $step |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function stepIsValid(Step $step) |
||
99 | |||
100 | /** |
||
101 | * Searches for the first invalid step among previous steps from the given |
||
102 | * step. |
||
103 | * |
||
104 | * All previous steps are listed, then for each one we check if submitted |
||
105 | * form values has been saved in the step persistence, in which case the |
||
106 | * step validation is launched again with the current form configuration. |
||
107 | * |
||
108 | * @param Step $step |
||
109 | * @return Step|null |
||
110 | */ |
||
111 | public function getFirstInvalidStep(Step $step) |
||
165 | |||
166 | /** |
||
167 | * Redirects the current request to the given step. |
||
168 | * |
||
169 | * @param Step $step |
||
170 | * @param Redirect $redirect |
||
171 | */ |
||
172 | public function redirectToStep(Step $step, Redirect $redirect) |
||
185 | |||
186 | /** |
||
187 | * @param Step $step |
||
188 | * @return StepDefinition|null |
||
189 | */ |
||
190 | public function getStepDefinition(Step $step) |
||
206 | |||
207 | /** |
||
208 | * Validates (again) the given step with the form data that were previously |
||
209 | * submitted and fetched from the step persistence. |
||
210 | * |
||
211 | * @param Step $step |
||
212 | * @return FormResult |
||
213 | */ |
||
214 | protected function validateStep(Step $step) |
||
240 | |||
241 | /** |
||
242 | * @return FormStepPersistence |
||
243 | */ |
||
244 | protected function getStepPersistence() |
||
254 | |||
255 | /** |
||
256 | * @return StepDefinition |
||
257 | */ |
||
258 | protected function getFirstStepDefinition() |
||
262 | } |
||
263 |