1 | <?php |
||
2 | |||
3 | namespace BeyondCode\QueryDetector; |
||
4 | |||
5 | use Closure; |
||
6 | |||
7 | class QueryDetectorMiddleware |
||
8 | { |
||
9 | /** @var QueryDetector */ |
||
10 | private $detector; |
||
11 | |||
12 | public function __construct(QueryDetector $detector) |
||
13 | { |
||
14 | $this->detector = $detector; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Handle an incoming request. |
||
19 | * |
||
20 | * @param Request $request |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
21 | * @param Closure $next |
||
22 | * @return mixed |
||
23 | */ |
||
24 | public function handle($request, Closure $next) |
||
25 | { |
||
26 | if (! $this->detector->isEnabled()) { |
||
27 | return $next($request); |
||
28 | } |
||
29 | |||
30 | $this->detector->boot(); |
||
31 | |||
32 | /** @var \Illuminate\Http\Response $response */ |
||
33 | $response = $next($request); |
||
34 | |||
35 | // Modify the response to add the Debugbar |
||
36 | $this->detector->output($request, $response); |
||
37 | |||
38 | return $response; |
||
39 | } |
||
40 | } |