| 199 |
lars |
1 |
<?php namespace Clockwork\Support\Laravel;
|
|
|
2 |
|
|
|
3 |
use Illuminate\Contracts\Debug\ExceptionHandler;
|
|
|
4 |
use Illuminate\Contracts\Foundation\Application;
|
|
|
5 |
|
|
|
6 |
// Clockwork Laravel middleware
|
|
|
7 |
class ClockworkMiddleware
|
|
|
8 |
{
|
|
|
9 |
// Laravel application instance
|
|
|
10 |
protected $app;
|
|
|
11 |
|
|
|
12 |
// Create a new middleware instance
|
|
|
13 |
public function __construct(Application $app)
|
|
|
14 |
{
|
|
|
15 |
$this->app = $app;
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
// Handle an incoming request
|
|
|
19 |
public function handle($request, \Closure $next)
|
|
|
20 |
{
|
|
|
21 |
$this->app['clockwork']->event('Controller')->begin();
|
|
|
22 |
|
|
|
23 |
try {
|
|
|
24 |
$response = $next($request);
|
|
|
25 |
} catch (\Exception $e) {
|
|
|
26 |
$this->app[ExceptionHandler::class]->report($e);
|
|
|
27 |
$response = $this->app[ExceptionHandler::class]->render($request, $e);
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
return $this->app['clockwork.support']->processRequest($request, $response);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
// Record the current request after a response is sent
|
|
|
34 |
public function terminate()
|
|
|
35 |
{
|
|
|
36 |
$this->app['clockwork.support']->recordRequest();
|
|
|
37 |
}
|
|
|
38 |
}
|