Total Complexity | 7 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class SetRepository |
||
10 | { |
||
11 | private Cache\CacheItemPoolInterface $cache; |
||
12 | |||
13 | public function __construct(Cache\CacheItemPoolInterface $cache) |
||
14 | { |
||
15 | $this->cache = $cache; |
||
16 | } |
||
17 | |||
18 | public function saveFeatureSet(Set $set): void |
||
19 | { |
||
20 | $cacheItem = $this->cache->getItem(self::generateFeatureSetCacheKey()); |
||
21 | $cacheItem->set($set); |
||
22 | |||
23 | $this->cache->save($cacheItem); |
||
24 | } |
||
25 | |||
26 | public function getFeatureSet(SetProviderInterface $fallback = null): Set |
||
27 | { |
||
28 | $result = $this->cache->getItem(self::generateFeatureSetCacheKey())->get(); |
||
29 | |||
30 | if (!$result && $fallback) { |
||
31 | $result = $fallback->getFeatureSet(); |
||
32 | $this->saveFeatureSet($fallback->getFeatureSet()); |
||
33 | } |
||
34 | |||
35 | return ($result) ?? new Set(); |
||
36 | } |
||
37 | |||
38 | public function deleteFeatureSet(): void |
||
39 | { |
||
40 | $this->cache->deleteItem(self::generateFeatureSetCacheKey()); |
||
41 | } |
||
42 | |||
43 | public static function generateFeatureSetCacheKey(): string |
||
46 | } |
||
47 | } |
||
48 |