CacheEventListener::onDelete()   A
last analyzed

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
namespace PhpCache\Example\EventListener;
4
5
use DateTimeImmutable;
6
use DateTimeZone;
7
use PhpCache\CacheEventListener\CacheEventListenerInterface;
8
use PhpCache\Example\Logger\LogEntry;
9
10
/**
11
 * Description of CacheEventListener.
12
 *
13
 * @author kdudas
14
 */
15
class CacheEventListener implements CacheEventListenerInterface
16
{
17
    private $logger;
18
19
    public function __construct($logger)
20
    {
21
        $this->logger = $logger;
22
    }
23
24
    public function onDelete($key, $entry)
25
    {
26
        $logEntry = new LogEntry(
27
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
28
            LogEntry::SEVERITY_INFO,
29
            'Cache Entry with key '.$key.' deleted'
30
        );
31
32
        $this->logger->log($logEntry);
33
34
        return $entry;
35
    }
36
37
    public function onGet($key, $entry)
38
    {
39
        $logEntry = new LogEntry(
40
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
41
            LogEntry::SEVERITY_INFO,
42
            'Cache Entry with key '.$key.' requested'
43
        );
44
45
        $this->logger->log($logEntry);
46
47
        return $entry;
48
    }
49
50
    public function onSet($key, $entry)
51
    {
52
        $logEntry = new LogEntry(
53
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
54
            LogEntry::SEVERITY_INFO,
55
            'Cache Entry with key '.$key.' was set into cache pool'
56
        );
57
58
        $this->logger->log($logEntry);
59
60
        return $entry;
61
    }
62
}
63