1 | <?php |
||
36 | class StepMiddlewareService implements SingletonInterface |
||
37 | { |
||
38 | use SelfInstantiateTrait; |
||
39 | |||
40 | /** |
||
41 | * @var FormObject |
||
42 | */ |
||
43 | protected $formObject; |
||
44 | |||
45 | /** |
||
46 | * @var Request |
||
47 | */ |
||
48 | protected $request; |
||
49 | |||
50 | /** |
||
51 | * @var StepMiddlewareValidationService |
||
52 | */ |
||
53 | protected $validationService; |
||
54 | |||
55 | /** |
||
56 | * @var FormStepPersistence |
||
57 | */ |
||
58 | protected $persistence; |
||
59 | |||
60 | /** |
||
61 | * @param FormObject $formObject |
||
62 | * @param Request $request |
||
63 | */ |
||
64 | public function reset(FormObject $formObject, Request $request) |
||
73 | |||
74 | /** |
||
75 | * @param Step $currentStep |
||
76 | * @return StepDefinition|null |
||
77 | */ |
||
78 | public function getNextStep(Step $currentStep) |
||
102 | |||
103 | // @todo tmp-delete? |
||
104 | // /** |
||
105 | // * Saves the submitted values in the metadata, for the given step. |
||
106 | // * |
||
107 | // * @param Step $currentStep |
||
108 | // */ |
||
109 | // public function saveStepFormValues(Step $currentStep) |
||
110 | // { |
||
111 | // $this->persistence->addStepFormValues($this->getStepDefinition($currentStep), $this->getFormRawValues()); |
||
112 | // } |
||
113 | // |
||
114 | // /** |
||
115 | // * Fetches the raw values sent in the request. |
||
116 | // * |
||
117 | // * @return array |
||
118 | // * @throws InvalidArgumentTypeException |
||
119 | // */ |
||
120 | // protected function getFormRawValues() |
||
121 | // { |
||
122 | // $formName = $this->getFormObject()->getName(); |
||
123 | // $formArray = null; |
||
124 | // |
||
125 | // if ($this->request->hasArgument($formName)) { |
||
126 | // /** @var array $formArray */ |
||
127 | // $formArray = $this->request->getArgument($formName); |
||
128 | // |
||
129 | // if (false === is_array($formArray)) { |
||
130 | // throw InvalidArgumentTypeException::formArgumentNotArray($this->getFormObject(), $formArray); |
||
131 | // } |
||
132 | // } else { |
||
133 | // $formArray = []; |
||
134 | // } |
||
135 | // |
||
136 | // return $formArray; |
||
137 | // } |
||
138 | // |
||
139 | // /** |
||
140 | // * @see \Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareValidationService::markStepAsValidated() |
||
141 | // * |
||
142 | // * @param StepDefinition $stepDefinition |
||
143 | // * @param array $formValues |
||
144 | // */ |
||
145 | // public function markStepAsValidated(StepDefinition $stepDefinition, array $formValues) |
||
146 | // { |
||
147 | // $this->validationService->markStepAsValidated($stepDefinition, $formValues); |
||
148 | // } |
||
149 | |||
150 | /** |
||
151 | * @see \Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareValidationService::addValidatedFields |
||
152 | * |
||
153 | * @param array $validatedFields |
||
154 | */ |
||
155 | public function addValidatedFields(array $validatedFields) |
||
159 | |||
160 | /** |
||
161 | * @see \Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareValidationService::stepDefinitionIsValid |
||
162 | * |
||
163 | * @param StepDefinition $stepDefinition |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function stepIsValid(StepDefinition $stepDefinition) |
||
170 | |||
171 | /** |
||
172 | * @see \Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareValidationService::getFirstInvalidStep |
||
173 | * |
||
174 | * @param Step $step |
||
175 | * @return StepDefinition|null |
||
176 | */ |
||
177 | public function getFirstInvalidStep(Step $step) |
||
181 | |||
182 | /** |
||
183 | * @param StepDefinition $step |
||
184 | * @return StepDefinition |
||
185 | */ |
||
186 | public function getNextStepDefinition(StepDefinition $step) |
||
221 | |||
222 | public function getNextSubstepDefinition(SubstepDefinition $substepDefinition) |
||
249 | |||
250 | public function findSubstepDefinition(Step $step, callable $callback) |
||
254 | |||
255 | /** |
||
256 | * Finds the first valid substep. |
||
257 | * |
||
258 | * @param Step $step |
||
259 | * @return SubstepDefinition|null |
||
260 | */ |
||
261 | public function findFirstSubstepDefinition(Step $step) |
||
269 | |||
270 | protected function findSubstepDefinitionRecursive(SubstepDefinition $substepDefinition, callable $callback) |
||
284 | |||
285 | /** |
||
286 | * @param StepDefinition $stepDefinition |
||
287 | * @param Redirect $redirect |
||
288 | */ |
||
289 | public function moveForwardToStep(StepDefinition $stepDefinition, Redirect $redirect) |
||
294 | |||
295 | /** |
||
296 | * Redirects the current request to the given step. |
||
297 | * |
||
298 | * @param Step $step |
||
299 | * @param Redirect $redirect |
||
300 | */ |
||
301 | public function redirectToStep(Step $step, Redirect $redirect) |
||
314 | |||
315 | /** |
||
316 | * @param StepDefinition $stepDefinition |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function getStepDefinitionConditionResult(StepDefinition $stepDefinition) |
||
328 | |||
329 | /** |
||
330 | * @param SubstepDefinition $substepDefinition |
||
331 | * @return bool |
||
332 | */ |
||
333 | public function getSubstepDefinitionConditionResult(SubstepDefinition $substepDefinition) |
||
342 | |||
343 | private function substepIsValid(SubstepDefinition $substepDefinition) |
||
351 | |||
352 | /** |
||
353 | * @param Step $step |
||
354 | * @return StepDefinition|null |
||
355 | */ |
||
356 | public function getStepDefinition(Step $step) |
||
362 | |||
363 | /** |
||
364 | * @return FormStepPersistence |
||
365 | */ |
||
366 | public function getStepPersistence() |
||
370 | |||
371 | /** |
||
372 | * @return FormObject |
||
373 | */ |
||
374 | public function getFormObject() |
||
378 | |||
379 | /** |
||
380 | * @return StepDefinition |
||
381 | */ |
||
382 | public function getFirstStepDefinition() |
||
386 | } |
||
387 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: