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

ViewCacheHandler::serveCachedView()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
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