1 | <?php |
||
20 | final class FilesystemStorage implements StorageInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $directory; |
||
26 | |||
27 | 3 | public function __construct(string $directory) |
|
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 2 | public function get(string $key) |
|
36 | { |
||
37 | 2 | $filePath = $this->buildFilePath($key); |
|
38 | |||
39 | 2 | if (!is_file($filePath)) { |
|
40 | 1 | throw StorageRecordNotExistException::forKey($key); |
|
41 | } |
||
42 | |||
43 | 1 | $contents = file_get_contents($filePath); |
|
44 | |||
45 | 1 | return unserialize($contents); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 2 | public function set(string $key, $data) |
|
63 | |||
64 | 3 | private function buildFilePath(string $key) |
|
68 | } |
||
69 |