These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace DoctrineModule\Cache; |
||
6 | |||
7 | use Doctrine\Common\Cache\Cache; |
||
8 | use Doctrine\Common\Cache\CacheProvider; |
||
9 | use Laminas\Cache\Storage\AvailableSpaceCapableInterface; |
||
10 | use Laminas\Cache\Storage\FlushableInterface; |
||
11 | use Laminas\Cache\Storage\StorageInterface; |
||
12 | use Laminas\Cache\Storage\TotalSpaceCapableInterface; |
||
13 | |||
14 | /** |
||
15 | * Bridge class that allows usage of a Laminas Cache Storage as a Doctrine Cache |
||
16 | * |
||
17 | * @link http://www.doctrine-project.org/ |
||
18 | */ |
||
19 | class LaminasStorageCache extends CacheProvider |
||
20 | { |
||
21 | /** @var StorageInterface */ |
||
22 | protected $storage; |
||
23 | |||
24 | 5 | public function __construct(StorageInterface $storage) |
|
25 | { |
||
26 | 5 | $this->storage = $storage; |
|
27 | 5 | } |
|
28 | |||
29 | /** |
||
30 | * {@inheritDoc} |
||
31 | */ |
||
32 | 4 | protected function doFetch($id) |
|
33 | { |
||
34 | 4 | $hit = $this->storage->getItem($id); |
|
35 | |||
36 | 4 | return $hit ?? false; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritDoc} |
||
41 | */ |
||
42 | 4 | protected function doContains($id) |
|
43 | { |
||
44 | 4 | return $this->storage->hasItem($id); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritDoc} |
||
49 | */ |
||
50 | 4 | protected function doSave($id, $data, $lifeTime = false) |
|
51 | { |
||
52 | // @todo check if lifetime can be set |
||
53 | 4 | return $this->storage->setItem($id, $data); |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | 1 | protected function doDelete($id) |
|
60 | { |
||
61 | 1 | return $this->storage->removeItem($id); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | 1 | protected function doFlush() |
|
68 | { |
||
69 | 1 | if ($this->storage instanceof FlushableInterface) { |
|
70 | 1 | $storage = $this->storage; |
|
71 | |||
72 | 1 | return $storage->flush(); |
|
73 | } |
||
74 | |||
75 | return false; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | */ |
||
81 | 1 | protected function doGetStats() |
|
82 | { |
||
83 | 1 | $storage = $this->storage; |
|
84 | |||
85 | return [ |
||
86 | 1 | Cache::STATS_HITS => $this->storage->getMetadata(Cache::STATS_HITS), |
|
87 | 1 | Cache::STATS_MISSES => $this->storage->getMetadata(Cache::STATS_MISSES), |
|
88 | 1 | Cache::STATS_UPTIME => $this->storage->getMetadata(Cache::STATS_UPTIME), |
|
89 | 1 | Cache::STATS_MEMORY_USAGE => $storage instanceof TotalSpaceCapableInterface |
|
90 | 1 | ? $storage->getTotalSpace() |
|
91 | : null, |
||
92 | 1 | Cache::STATS_MEMORY_AVAILIABLE => $storage instanceof AvailableSpaceCapableInterface |
|
0 ignored issues
–
show
|
|||
93 | 1 | ? $storage->getAvailableSpace() |
|
94 | : null, |
||
95 | ]; |
||
96 | } |
||
97 | } |
||
98 |
This class constant has been deprecated.