Passed
Push — master ( 7cbfe3...bc244d )
by Krisztián
05:18
created

CacheEventListener::onGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * All rights reserved © 2018 Legow Hosting Kft.
5
 */
6
7
namespace PhpCache\Example\EventListener;
8
9
use DateTimeImmutable;
10
use DateTimeZone;
11
use PhpCache\CacheEventListener\CacheEventListenerInterface;
12
use PhpCache\Example\Logger\LogEntry;
13
14
/**
15
 * Description of CacheEventListener.
16
 *
17
 * @author kdudas
18
 */
19
class CacheEventListener implements CacheEventListenerInterface
20
{
21
    private $logger;
22
23
    public function __construct($logger)
24
    {
25
        $this->logger = $logger;
26
    }
27
28
    public function onDelete($key, $entry)
29
    {
30
        $logEntry = new LogEntry(
31
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
32
            LogEntry::SEVERITY_INFO,
33
            'Cache Entry with key '.$key.' deleted'
34
        );
35
36
        $this->logger->log($logEntry);
37
38
        return $entry;
39
    }
40
41
    public function onGet($key, $entry)
42
    {
43
        $logEntry = new LogEntry(
44
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
45
            LogEntry::SEVERITY_INFO,
46
            'Cache Entry with key '.$key.' requested'
47
        );
48
49
        $this->logger->log($logEntry);
50
51
        return $entry;
52
    }
53
54
    public function onSet($key, $entry)
55
    {
56
        $logEntry = new LogEntry(
57
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
58
            LogEntry::SEVERITY_INFO,
59
            'Cache Entry with key '.$key.' was set into cache pool'
60
        );
61
62
        $this->logger->log($logEntry);
63
64
        return $entry;
65
    }
66
}
67