Passed
Push — master ( 39ef33...5f4097 )
by Arman
03:00 queued 15s
created

ViewCacheHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A serveCachedView() 0 8 3
1
<?php
2
3
namespace Quantum\Handlers;
4
5
use Quantum\Libraries\ResourceCache\ViewCache;
6
use Quantum\Http\Response;
7
8
class ViewCacheHandler
9
{
10
    protected ViewCache $viewCache;
11
12
    public function __construct()
13
    {
14
        $this->viewCache = ViewCache::getInstance();
15
    }
16
17
/**
18
 * Serves a cached view if it exists and caching is enabled.
19
 *
20
 * @param string $uri The URI of the view to serve.
21
 * @param Response $response The Response object to send the cached view to.
22
 * @return bool True if a cached view was served, false otherwise.
23
 */
24
    public function serveCachedView(string $uri, Response $response): bool
25
    {
26
        if ($this->viewCache->isEnabled() && $this->viewCache->exists($uri)) {
27
            $response->html($this->viewCache->get($uri));
28
            return true;
29
        }
30
31
        return false;
32
    }
33
}
34