1 | <?php |
||
32 | class MiddlewareState |
||
33 | { |
||
34 | /** |
||
35 | * @var MiddlewareInterface[] |
||
36 | */ |
||
37 | protected $list = []; |
||
38 | |||
39 | /** |
||
40 | * @var FormObject |
||
41 | */ |
||
42 | protected $formObject; |
||
43 | |||
44 | /** |
||
45 | * @var Request |
||
46 | */ |
||
47 | protected $request; |
||
48 | |||
49 | /** |
||
50 | * @var Arguments |
||
51 | */ |
||
52 | protected $requestArguments; |
||
53 | |||
54 | /** |
||
55 | * @see getSignalSortedMiddlewares() |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $signalSortedMiddlewares = []; |
||
60 | |||
61 | /** |
||
62 | * @param FormObject $formObject |
||
63 | * @param FormzControllerContext $formzControllerContext |
||
64 | */ |
||
65 | public function __construct(FormObject $formObject, FormzControllerContext $formzControllerContext) |
||
76 | |||
77 | /** |
||
78 | * Will run and process trough every middleware registered for the current |
||
79 | * form object. |
||
80 | */ |
||
81 | public function run() |
||
91 | |||
92 | /** |
||
93 | * Will dispatch the before-signal from a given source to all middlewares |
||
94 | * bound to the signal. |
||
95 | * |
||
96 | * @param SendsMiddlewareSignal $source |
||
97 | */ |
||
98 | public function dispatchBeforeSignal(SendsMiddlewareSignal $source) |
||
108 | |||
109 | /** |
||
110 | * Will dispatch the after-signal from a given source to all middlewares |
||
111 | * bound to the signal. |
||
112 | * |
||
113 | * @param SendsMiddlewareSignal $source |
||
114 | */ |
||
115 | public function dispatchAfterSignal(SendsMiddlewareSignal $source) |
||
125 | |||
126 | /** |
||
127 | * Returns the sorted list of middlewares bound to the given signal name. |
||
128 | * |
||
129 | * @param string $signalName |
||
130 | * @return array |
||
131 | */ |
||
132 | protected function getMiddlewaresBoundToSignal($signalName) |
||
133 | { |
||
134 | $signalSortedMiddlewares = $this->getSignalSortedMiddlewares(); |
||
135 | |||
136 | return (isset($signalSortedMiddlewares[$signalName])) |
||
137 | ? $signalSortedMiddlewares[$signalName] |
||
138 | : []; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Returns a sorted list of the registered middlewares: the first level is |
||
143 | * the signal used by the group, and the second level is the group of |
||
144 | * middlewares, sorted by descendant priority of each middleware. |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | protected function getSignalSortedMiddlewares() |
||
171 | |||
172 | /** |
||
173 | * Will sort and return a middlewares list based on the priority of each |
||
174 | * middleware. The middlewares with the highest priority will be placed at |
||
175 | * the top of the list. |
||
176 | * |
||
177 | * @param array $list |
||
178 | * @return array |
||
179 | */ |
||
180 | private function sortMiddlewaresListByPriority(array $list) |
||
197 | |||
198 | /** |
||
199 | * @return FormObject |
||
200 | */ |
||
201 | public function getFormObject() |
||
205 | |||
206 | /** |
||
207 | * @return Request |
||
208 | */ |
||
209 | public function getRequest() |
||
213 | |||
214 | /** |
||
215 | * @return Arguments |
||
216 | */ |
||
217 | public function getRequestArguments() |
||
221 | } |
||
222 |