1 | <?php |
||
25 | class MiddlewarePipeline |
||
26 | { |
||
27 | use JsonTrait, MiddlewaresTrait; |
||
28 | |||
29 | /** |
||
30 | * @invisible |
||
31 | * @var ContainerInterface |
||
32 | */ |
||
33 | private $container; |
||
34 | |||
35 | /** |
||
36 | * Endpoint should be called at the deepest level of pipeline. |
||
37 | * |
||
38 | * @var callable |
||
39 | */ |
||
40 | private $target = null; |
||
41 | |||
42 | /** |
||
43 | * @param callable[]|MiddlewareInterface[] $middlewares |
||
44 | * @param ContainerInterface $container Spiral container is needed, due scoping. |
||
45 | * |
||
46 | * @throws ScopeException |
||
47 | */ |
||
48 | public function __construct(array $middlewares = [], ContainerInterface $container) |
||
53 | |||
54 | /** |
||
55 | * Set pipeline target. |
||
56 | * |
||
57 | * @param callable $target |
||
58 | * |
||
59 | * @return $this|self |
||
60 | */ |
||
61 | public function target(callable $target): MiddlewarePipeline |
||
67 | |||
68 | /** |
||
69 | * @param Request $request |
||
70 | * @param Response $response |
||
71 | * |
||
72 | * @return Response |
||
73 | */ |
||
74 | public function __invoke(Request $request, Response $response): Response |
||
78 | |||
79 | /** |
||
80 | * Pass request and response though every middleware to target and return generated and wrapped |
||
81 | * response. |
||
82 | * |
||
83 | * @param Request $request |
||
84 | * @param Response $response |
||
85 | * |
||
86 | * @return Response |
||
87 | * |
||
88 | * @throws MiddlewareException |
||
89 | */ |
||
90 | public function run(Request $request, Response $response): Response |
||
98 | |||
99 | /** |
||
100 | * Get next chain to be called. Exceptions will be converted to responses. |
||
101 | * |
||
102 | * @param int $position |
||
103 | * @param Request $request |
||
104 | * @param Response $response |
||
105 | * |
||
106 | * @return null|Response |
||
107 | * @throws \Exception |
||
108 | */ |
||
109 | protected function next(int $position, Request $request, Response $response) |
||
129 | |||
130 | /** |
||
131 | * Run pipeline target and return generated response. |
||
132 | * |
||
133 | * @param Request $request |
||
134 | * @param Response $response |
||
135 | * |
||
136 | * @return Response |
||
137 | * |
||
138 | * @throws \Throwable |
||
139 | */ |
||
140 | protected function mountResponse(Request $request, Response $response): Response |
||
171 | |||
172 | /** |
||
173 | * Convert endpoint result into valid response. |
||
174 | * |
||
175 | * @param Response $response Initial pipeline response. |
||
176 | * @param mixed $result Generated endpoint output. |
||
177 | * @param string $output Buffer output. |
||
178 | * |
||
179 | * @return Response |
||
180 | */ |
||
181 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
||
202 | |||
203 | /** |
||
204 | * Get next callable element. |
||
205 | * |
||
206 | * @param int $position |
||
207 | * @param Request $outerRequest |
||
208 | * @param Response $outerResponse |
||
209 | * |
||
210 | * @return \Closure |
||
211 | */ |
||
212 | private function getNext( |
||
232 | } |
||
233 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: