1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\Middleware\Item\Step; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Configuration\Form\Step\Step\Step; |
17
|
|
|
use Romm\Formz\Middleware\Argument\Arguments; |
18
|
|
|
use Romm\Formz\Middleware\Item\AbstractMiddleware; |
19
|
|
|
use Romm\Formz\Middleware\Item\FormValidation\FormValidationSignal; |
20
|
|
|
use Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareService; |
21
|
|
|
use Romm\Formz\Middleware\Signal\Before; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @todo |
25
|
|
|
*/ |
26
|
|
|
class StepFetchingMiddleware extends AbstractMiddleware implements Before, FormValidationSignal |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
protected $priority = self::PRIORITY_STEP; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var StepMiddlewareService |
35
|
|
|
*/ |
36
|
|
|
protected $service; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @todo |
40
|
|
|
*/ |
41
|
|
|
public function initializeMiddleware() |
42
|
|
|
{ |
43
|
|
|
$this->service = StepMiddlewareService::get(); |
44
|
|
|
$this->service->reset($this->getFormObject()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Arguments $arguments |
49
|
|
|
*/ |
50
|
|
|
public function before(Arguments $arguments) |
51
|
|
|
{ |
52
|
|
|
$formObject = $this->getFormObject(); |
53
|
|
|
|
54
|
|
|
if (false === $formObject->getConfiguration()->hasSteps()) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$currentStep = $this->getCurrentStep(); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
if ($currentStep) { |
62
|
|
|
$stepToRedirect = $this->service->validateStep($currentStep); |
63
|
|
|
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($currentStep, '$currentStep'); |
64
|
|
|
|
65
|
|
|
if ($stepToRedirect instanceof Step) { |
66
|
|
|
die(); |
|
|
|
|
67
|
|
|
$this->redirectToStep($stepToRedirect); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function redirectToStep(Step $step) |
73
|
|
|
{ |
74
|
|
|
$formObject = $this->getFormObject(); |
75
|
|
|
|
76
|
|
|
$this->redirect() |
77
|
|
|
->toPage($step->getPageUid()) |
78
|
|
|
->toExtension($step->getExtension()) |
79
|
|
|
->toController($step->getController()) |
80
|
|
|
->toAction($step->getAction()) |
81
|
|
|
->withArguments([ |
82
|
|
|
'fz-hash' => [ |
83
|
|
|
$formObject->getName() => $formObject->getFormHash() |
84
|
|
|
] |
85
|
|
|
]) |
86
|
|
|
->dispatch(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.