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 |
||
19 | public function getExecutionChain(Route $route, array $vars) |
||
20 | { |
||
21 | 12 | $middleware = function ( |
|
22 | ServerRequestInterface $request, ResponseInterface $response, callable $next |
||
23 | ) use ( |
||
24 | 12 | $route, $vars |
|
25 | ) { |
||
26 | 12 | $response = call_user_func_array($route->getCallable(), [$request, $response, $vars]); |
|
27 | |||
28 | 9 | if (! $response instanceof ResponseInterface) { |
|
29 | 3 | throw new RuntimeException( |
|
30 | 'Route callables must return an instance of (Psr\Http\Message\ResponseInterface)' |
||
31 | 3 | ); |
|
32 | } |
||
33 | |||
34 | 6 | return $next($request, $response); |
|
35 | 12 | }; |
|
36 | |||
37 | 12 | $execChain = (new ExecutionChain)->middleware($middleware); |
|
38 | |||
39 | // ensure middleware is executed in the order it was added |
||
40 | 12 | $stack = array_reverse($route->getMiddlewareStack()); |
|
41 | |||
42 | 12 | foreach ($stack as $middleware) { |
|
43 | 3 | $execChain->middleware($middleware); |
|
44 | 12 | } |
|
45 | |||
46 | 12 | return $execChain; |
|
47 | } |
||
48 | |||
73 |