Total Complexity | 4 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
5 | class FileCacheDriver extends AbstractCacheDriver |
||
6 | { |
||
7 | /** |
||
8 | * The config of the driver. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $config = [ |
||
13 | 'path' => '', |
||
14 | 'timezone' => 'America/Santo_Domingo', |
||
15 | ]; |
||
16 | |||
17 | /** |
||
18 | * Creates a new FileCacheDriver instance. |
||
19 | * |
||
20 | * @param array $config |
||
21 | */ |
||
22 | 4 | public function __construct(array $config) |
|
23 | { |
||
24 | 4 | $this->config = $config; |
|
25 | 4 | } |
|
26 | |||
27 | /** |
||
28 | * {@inheritDoc} |
||
29 | */ |
||
30 | 4 | public function add($key, $value) |
|
31 | { |
||
32 | 4 | $filename = sprintf('%s/%s.txt', $this->config['path'], $key); |
|
33 | 4 | $file = fopen($filename, 'w'); |
|
34 | |||
35 | 4 | fwrite($file, serialize($value)); |
|
|
|||
36 | 4 | fclose($file); |
|
37 | 4 | $this->keys[] = $key; |
|
38 | 4 | } |
|
39 | |||
40 | /** |
||
41 | * {@inheritDoc} |
||
42 | */ |
||
43 | 1 | public function get($key) |
|
44 | { |
||
45 | 1 | $filename = sprintf('%s/%s.txt', $this->config['path'], $key); |
|
46 | 1 | $file = fopen($filename, 'r'); |
|
47 | 1 | $content = fread($file, filesize($filename)); |
|
48 | |||
49 | 1 | return unserialize($content); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritDoc} |
||
54 | */ |
||
55 | 1 | public function remove($key) |
|
58 | 1 | } |
|
59 | } |
||
60 |