Completed
Push — master ( c0e612...954278 )
by Jasper
04:23
created

CacheMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Swis\Laravel\StaticRequestCache\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Swis\Laravel\StaticRequestCache\StaticRequestCache;
8
use Symfony\Component\HttpFoundation\Response;
9
10
class CacheMiddleware
11
{
12
    /**
13
     * @var \Swis\Laravel\StaticRequestCache\StaticRequestCache
14
     */
15
    protected $staticRequestCache;
16
17
    /**
18
     * @param \Swis\Laravel\StaticRequestCache\StaticRequestCache $staticRequestCache
19
     */
20 35
    public function __construct(StaticRequestCache $staticRequestCache)
21
    {
22 35
        $this->staticRequestCache = $staticRequestCache;
23 35
    }
24
25
    /**
26
     * Handle an incoming request.
27
     *
28
     * @param  Request $request
29
     * @param  \Closure $next
30
     * @return mixed
31
     */
32 7
    public function handle($request, Closure $next)
33
    {
34 7
        return $next($request);
35
    }
36
37
    /**
38
     * @param \Illuminate\Http\Request                   $request
39
     * @param \Symfony\Component\HttpFoundation\Response $response
40
     */
41 20
    public function terminate(Request $request, Response $response)
42
    {
43 8
        $store = function () use ($request, $response) {
44 28
            if ($this->staticRequestCache->shouldStoreResponse($request, $response)) {
45 21
                $this->staticRequestCache->store($request, $response);
46
            }
47 28
        };
48
49 28
        if (config('static-html-cache.graceful')) {
50 21
            rescue($store);
51
        } else {
52 7
            $store();
53
        }
54 21
    }
55
}
56