1 | <?php |
||
14 | class JsonStrategy implements StrategyInterface |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | 9 | public function getCallable(Route $route, array $vars) |
|
20 | { |
||
21 | return function (ServerRequestInterface $request, ResponseInterface $response, callable $next) use ($route, $vars) { |
||
22 | 9 | $return = call_user_func_array($route->getCallable(), [$request, $response, $vars]); |
|
23 | |||
24 | 3 | if (! $return instanceof ResponseInterface) { |
|
25 | 3 | throw new RuntimeException( |
|
26 | 'Route callables must return an instance of (Psr\Http\Message\ResponseInterface)' |
||
27 | 3 | ); |
|
28 | } |
||
29 | |||
30 | $response = $return; |
||
31 | $response = $next($request, $response); |
||
32 | |||
33 | return $response->withAddedHeader('content-type', 'application/json'); |
||
34 | 9 | }; |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | 3 | public function getNotFoundDecorator(NotFoundException $exception) |
|
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 3 | public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception) |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function getExceptionDecorator(Exception $exception) |
||
76 | } |
||
77 |