1 | <?php |
||
7 | class XrayMiddleware |
||
8 | { |
||
9 | |||
10 | /** @var Xray */ |
||
11 | private $xray; |
||
12 | |||
13 | public function __construct(Xray $xray) |
||
17 | |||
18 | /** |
||
19 | * Handle an incoming request. |
||
20 | * |
||
21 | * @param Request $request |
||
22 | * @param Closure $next |
||
23 | * @return mixed |
||
24 | */ |
||
25 | public function handle($request, Closure $next) |
||
26 | { |
||
27 | if (! $this->xray->isEnabled()) { |
||
28 | return $next($request); |
||
29 | } |
||
30 | |||
31 | $this->xray->boot(); |
||
32 | |||
33 | /** @var \Illuminate\Http\Response $response */ |
||
34 | $response = $next($request); |
||
35 | |||
36 | if ($response->isRedirection()) { |
||
37 | return $response; |
||
38 | } elseif ( |
||
39 | ($response->headers->has('Content-Type') && |
||
40 | strpos($response->headers->get('Content-Type'), 'html') === false) |
||
41 | || $request->getRequestFormat() !== 'html' |
||
42 | || $response->getContent() === false |
||
43 | ) { |
||
44 | return $response; |
||
45 | } elseif (is_null($response->exception) && !is_null($this->xray->getBaseView())) { |
||
46 | // Modify the response to add the Debugbar |
||
47 | $this->injectXrayBar($response); |
||
48 | } |
||
49 | return $response; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get the route information for a given route. |
||
54 | * |
||
55 | * @param \Illuminate\Routing\Route $route |
||
56 | * @return array |
||
57 | */ |
||
58 | protected function getRouteInformation($route) |
||
91 | |||
92 | protected function injectXrayBar($response) |
||
118 | } |