Conditions | 3 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
12 | public function handle(Request $request, Closure $next) |
||
13 | { |
||
14 | /** |
||
15 | * @var \Symfony\Component\HttpFoundation\Response $response |
||
16 | */ |
||
17 | $response = $next($request); |
||
18 | |||
19 | // In case the request was sent by Api Tester |
||
20 | // and catching request is wanted |
||
21 | // we will halt the response and output redirect information instead. |
||
22 | if ($request->header('X-Api-Tester') === static::CATCH_REDIRECT_HEADER) { |
||
23 | if ($response->isRedirection()) { |
||
24 | /** |
||
25 | * @var \Symfony\Component\HttpFoundation\RedirectResponse $response |
||
26 | */ |
||
27 | return response()->json(['data' => [ |
||
28 | 'location' => $response->getTargetUrl(), |
||
29 | 'status' => $response->getStatusCode(), |
||
30 | ]])->header('X-Api-Tester', 'redirect'); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | return $response; |
||
35 | } |
||
36 | |||
37 | } |