Conditions | 5 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
22 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
23 | { |
||
24 | $response = $handler->handle($request); |
||
25 | $env = $request->getServerParams(); |
||
26 | if ($env['APP_ENV'] === 'development') { |
||
27 | return $response; |
||
28 | } |
||
29 | |||
30 | if ($request->getMethod() !== 'GET' || !in_array($response->getStatusCode(), $this->cacheableStatus)) { |
||
31 | return $response; |
||
32 | } |
||
33 | |||
34 | $maxLifetime = isset($env['CACHE_TIME']) ? (int)$env['CACHE_TIME'] : 3600; // cache for 1 hour |
||
35 | |||
36 | return $response->withAddedHeader( |
||
37 | 'Cache-Control', |
||
38 | "public, max-age=$maxLifetime" |
||
39 | )->withAddedHeader( |
||
40 | 'Expires', |
||
41 | gmdate("D, d M Y H:i:s", time() + $maxLifetime) . " GMT" |
||
42 | ); |
||
45 |