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\Form\Definition\Middleware; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor; |
17
|
|
|
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface; |
18
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\MagicMethodsTrait; |
19
|
|
|
use Romm\Formz\Middleware\Item\Field\Focus\FieldFocusMiddleware; |
20
|
|
|
use Romm\Formz\Middleware\Item\FormInjection\FormInjectionMiddleware; |
21
|
|
|
use Romm\Formz\Middleware\Item\FormValidation\FormValidationMiddleware; |
22
|
|
|
use Romm\Formz\Middleware\Item\Persistence\PersistenceFetchingMiddleware; |
23
|
|
|
use Romm\Formz\Middleware\Item\Step\PreviousStepMiddleware; |
24
|
|
|
use Romm\Formz\Middleware\Item\Step\StepDispatchingMiddleware; |
25
|
|
|
use Romm\Formz\Middleware\Item\Step\StepFetchingMiddleware; |
26
|
|
|
use Romm\Formz\Middleware\MiddlewareInterface; |
27
|
|
|
|
28
|
|
|
class PresetMiddlewares implements DataPreProcessorInterface |
29
|
|
|
{ |
30
|
|
|
use MagicMethodsTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \Romm\Formz\Middleware\Item\FormInjection\FormInjectionMiddleware |
34
|
|
|
*/ |
35
|
|
|
protected $formInjectionMiddleware; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Romm\Formz\Middleware\Item\FormValidation\FormValidationMiddleware |
39
|
|
|
*/ |
40
|
|
|
protected $formValidationMiddleware; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \Romm\Formz\Middleware\Item\Persistence\PersistenceFetchingMiddleware |
44
|
|
|
*/ |
45
|
|
|
protected $persistenceFetchingMiddleware; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \Romm\Formz\Middleware\Item\Step\PreviousStepMiddleware |
49
|
|
|
*/ |
50
|
|
|
protected $previousStepMiddleware; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \Romm\Formz\Middleware\Item\Step\StepFetchingMiddleware |
54
|
|
|
*/ |
55
|
|
|
protected $stepFetchingMiddleware; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var \Romm\Formz\Middleware\Item\Step\StepDispatchingMiddleware |
59
|
|
|
*/ |
60
|
|
|
protected $stepDispatchingMiddleware; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var \Romm\Formz\Middleware\Item\Field\Focus\FieldFocusMiddleware |
64
|
|
|
*/ |
65
|
|
|
protected $fieldFocusMiddleware; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the full list of preset middlewares. |
69
|
|
|
* |
70
|
|
|
* @return MiddlewareInterface[] |
71
|
|
|
*/ |
72
|
|
|
public function getList() |
73
|
|
|
{ |
74
|
|
|
return get_object_vars($this); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Fills middlewares by default (if they are not filled in configuration). |
79
|
|
|
* |
80
|
|
|
* @param DataPreProcessor $processor |
81
|
|
|
*/ |
82
|
|
|
public static function dataPreProcessor(DataPreProcessor $processor) |
83
|
|
|
{ |
84
|
|
|
$data = $processor->getData(); |
85
|
|
|
|
86
|
|
|
foreach (array_keys(get_class_vars(self::class)) as $middleware) { |
87
|
|
|
if (false === isset($data[$middleware])) { |
88
|
|
|
$data[$middleware] = []; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$processor->setData($data); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return FormInjectionMiddleware |
97
|
|
|
*/ |
98
|
|
|
public function getFormInjectionMiddleware() |
99
|
|
|
{ |
100
|
|
|
return $this->formInjectionMiddleware; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return FormValidationMiddleware |
105
|
|
|
*/ |
106
|
|
|
public function getFormValidationMiddleware() |
107
|
|
|
{ |
108
|
|
|
return $this->formValidationMiddleware; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return PersistenceFetchingMiddleware |
113
|
|
|
*/ |
114
|
|
|
public function getPersistenceFetchingMiddleware() |
115
|
|
|
{ |
116
|
|
|
return $this->persistenceFetchingMiddleware; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return PreviousStepMiddleware |
121
|
|
|
*/ |
122
|
|
|
public function getPreviousStepMiddleware() |
123
|
|
|
{ |
124
|
|
|
return $this->previousStepMiddleware; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return StepFetchingMiddleware |
129
|
|
|
*/ |
130
|
|
|
public function getStepFetchingMiddleware() |
131
|
|
|
{ |
132
|
|
|
return $this->stepFetchingMiddleware; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return StepDispatchingMiddleware |
137
|
|
|
*/ |
138
|
|
|
public function getStepDispatchingMiddleware() |
139
|
|
|
{ |
140
|
|
|
return $this->stepDispatchingMiddleware; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return FieldFocusMiddleware |
145
|
|
|
*/ |
146
|
|
|
public function getFieldFocusMiddleware() |
147
|
|
|
{ |
148
|
|
|
return $this->fieldFocusMiddleware; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|