Conditions | 3 |
Paths | 2 |
Total Lines | 29 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 3 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function getExecutionChain(Route $route, array $vars) |
||
17 | { |
||
18 | 9 | $middleware = function ( |
|
19 | ServerRequestInterface $request, ResponseInterface $response, callable $next |
||
20 | ) use ( |
||
21 | 9 | $route, $vars |
|
22 | ) { |
||
23 | 9 | $response = call_user_func_array($route->getCallable(), [$request, $response, $vars]); |
|
24 | |||
25 | 9 | if (! $response instanceof ResponseInterface) { |
|
26 | 3 | throw new RuntimeException( |
|
27 | 'Route callables must return an instance of (Psr\Http\Message\ResponseInterface)' |
||
28 | 3 | ); |
|
29 | } |
||
30 | |||
31 | 6 | return $next($request, $response); |
|
32 | 9 | }; |
|
33 | |||
34 | 9 | $execChain = (new ExecutionChain)->middleware($middleware); |
|
35 | |||
36 | // ensure middleware is executed in the order it was added |
||
37 | 9 | $stack = array_reverse($route->getMiddlewareStack()); |
|
38 | |||
39 | 9 | foreach ($stack as $middleware) { |
|
40 | 3 | $execChain->middleware($middleware); |
|
41 | 9 | } |
|
42 | |||
43 | 9 | return $execChain; |
|
44 | } |
||
45 | } |
||
46 |