Total Complexity | 5 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class Manager extends BaseManager |
||
10 | { |
||
11 | /** |
||
12 | * @var Connection $conn |
||
13 | */ |
||
14 | private $conn; |
||
15 | |||
16 | private $ttl = 0; |
||
17 | |||
18 | private $prefix = '0'; |
||
19 | |||
20 | 5 | public function __construct( |
|
21 | int $capacity, |
||
22 | float $rate, |
||
23 | LoggerInterface $logger, |
||
24 | Connection $conn, |
||
25 | int $ttl = 0, |
||
26 | string $prefix = '', |
||
27 | ?SerializerInterface $serializer = null |
||
28 | ) { |
||
29 | 5 | parent::__construct($capacity, $rate, $logger, $serializer); |
|
30 | 5 | $this->conn = $conn; |
|
31 | 5 | $this->ttl = $ttl; |
|
32 | 5 | $this->prefix = $prefix; |
|
33 | 5 | } |
|
34 | |||
35 | 1 | protected function load(string $name) |
|
36 | { |
||
37 | 1 | return $this->conn->get($this->getKey($name)); |
|
38 | } |
||
39 | |||
40 | 2 | protected function save(string $name, $value) |
|
41 | { |
||
42 | 2 | if ($this->ttl > 0) { |
|
43 | 1 | $this->conn->setex($this->getKey($name), $this->ttl, $value); |
|
44 | } else { |
||
45 | 1 | $this->conn->set($this->getKey($name), $value); |
|
46 | } |
||
47 | 2 | } |
|
48 | |||
49 | 2 | protected function getKey(string $name): string |
|
52 | } |
||
53 | } |
||
54 |