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\Items; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Error\FormResult; |
17
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
18
|
|
|
use Romm\Formz\Form\FormObject; |
19
|
|
|
use Romm\Formz\Middleware\Exception\RedirectException; |
20
|
|
|
use Romm\Formz\Middleware\Exception\StopPropagationException; |
21
|
|
|
use Romm\Formz\Middleware\MiddlewareInterface; |
22
|
|
|
use Romm\Formz\Middleware\Signal\MiddlewareSignal; |
23
|
|
|
use Romm\Formz\Middleware\State\StateMiddlewareDependencyTrait; |
24
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments; |
25
|
|
|
use TYPO3\CMS\Extbase\Mvc\Web\Request; |
26
|
|
|
|
27
|
|
|
abstract class AbstractMiddleware implements MiddlewareInterface |
28
|
|
|
{ |
29
|
|
|
use StateMiddlewareDependencyTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $options |
33
|
|
|
*/ |
34
|
|
|
public function __construct(array $options = []) |
35
|
|
|
{ |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @todo |
40
|
|
|
*/ |
41
|
|
|
final public function initialize() |
42
|
|
|
{ |
43
|
|
|
// @todo add options handling |
44
|
|
|
|
45
|
|
|
$this->initializeMiddleware(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @todo |
50
|
|
|
*/ |
51
|
|
|
protected function initializeMiddleware() |
52
|
|
|
{ |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @todo |
57
|
|
|
*/ |
58
|
|
|
final protected function stopPropagation() |
59
|
|
|
{ |
60
|
|
|
throw new StopPropagationException; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @todo |
65
|
|
|
* |
66
|
|
|
* @param string $actionName |
67
|
|
|
* @param string $controllerName |
68
|
|
|
* @param string $extensionName |
69
|
|
|
* @param array $arguments |
70
|
|
|
*/ |
71
|
|
|
final protected function forward($actionName, $controllerName = null, $extensionName = null, array $arguments = []) |
72
|
|
|
{ |
73
|
|
|
$request = $this->getRequest(); |
74
|
|
|
|
75
|
|
|
$request->setControllerActionName($actionName); |
76
|
|
|
$request->setControllerName($controllerName); |
77
|
|
|
$request->setControllerExtensionName($extensionName); |
78
|
|
|
$request->setArguments($arguments); |
79
|
|
|
|
80
|
|
|
$this->stopPropagation(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @todo |
85
|
|
|
* |
86
|
|
|
* @param string $actionName |
87
|
|
|
* @param string $controllerName |
88
|
|
|
* @param string $extensionName |
89
|
|
|
* @param array $arguments |
90
|
|
|
* @param string $pageUid |
91
|
|
|
* @param int $delay |
92
|
|
|
* @param int $statusCode |
93
|
|
|
* @throws RedirectException |
94
|
|
|
*/ |
95
|
|
|
final protected function redirect( |
96
|
|
|
$actionName, |
97
|
|
|
$controllerName = null, |
98
|
|
|
$extensionName = null, |
99
|
|
|
array $arguments = null, |
100
|
|
|
$pageUid = null, |
101
|
|
|
$delay = 0, |
102
|
|
|
$statusCode = 303 |
103
|
|
|
) { |
104
|
|
|
throw new RedirectException( |
105
|
|
|
$actionName, |
106
|
|
|
$controllerName, |
107
|
|
|
$extensionName, |
108
|
|
|
$arguments, |
109
|
|
|
$pageUid, |
110
|
|
|
$delay, |
111
|
|
|
$statusCode |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return FormObject |
117
|
|
|
*/ |
118
|
|
|
final protected function getFormObject() |
119
|
|
|
{ |
120
|
|
|
return $this->state->getFormObject(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return FormResult |
125
|
|
|
*/ |
126
|
|
|
final protected function getResult() |
127
|
|
|
{ |
128
|
|
|
return $this->state->getResult(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return Request |
133
|
|
|
*/ |
134
|
|
|
final protected function getRequest() |
135
|
|
|
{ |
136
|
|
|
return $this->state->getRequest(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return Arguments |
141
|
|
|
*/ |
142
|
|
|
final protected function getArguments() |
143
|
|
|
{ |
144
|
|
|
return $this->state->getArguments(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
|
|
final protected function getSettings() |
151
|
|
|
{ |
152
|
|
|
return $this->state->getSettings(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return int |
157
|
|
|
*/ |
158
|
|
|
public function getPriority() |
159
|
|
|
{ |
160
|
|
|
return 0; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Returns the name of the signal on which this middleware is bound. |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
* @throws EntryNotFoundException |
168
|
|
|
*/ |
169
|
|
|
final public function getBoundSignalName() |
170
|
|
|
{ |
171
|
|
|
$interfaces = class_implements($this); |
172
|
|
|
|
173
|
|
|
foreach ($interfaces as $interface) { |
174
|
|
|
if (in_array(MiddlewareSignal::class, class_implements($interface))) { |
175
|
|
|
return $interface; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
throw new EntryNotFoundException('@todo'); // @todo |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|