Passed
Push — master ( 158252...631a8c )
by Maxim
02:44
created

HtmlCache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 4
1
<?php
2
3
namespace WebComplete\core\utils\cache;
4
5
class HtmlCache
6
{
7
8
    /**
9
     * @var CacheService
10
     */
11
    protected $cacheService;
12
    /**
13
     * @var string
14
     */
15
    protected $key;
16
    /**
17
     * @var int
18
     */
19
    protected $ttl;
20
    /**
21
     * @var array
22
     */
23
    protected $tags;
24
25
    /**
26
     * @param CacheService $cacheService
27
     * @param string $key
28
     * @param int $ttl
29
     * @param array $tags
30
     */
31
    public function __construct(CacheService $cacheService, string $key, int $ttl = null, array $tags = [])
32
    {
33
        $this->cacheService = $cacheService;
34
        $this->key = $key;
35
        $this->ttl = $ttl;
36
        $this->tags = $tags;
37
    }
38
39
    public function end()
40
    {
41
        $content = ob_get_contents();
42
        ob_end_clean();
43
        Cache::set($this->key, $content, $this->ttl, $this->tags);
44
        echo $content;
45
    }
46
}
47