1 | <?php |
||
20 | class CacheServiceDecorator |
||
21 | { |
||
22 | const SPI_CACHE_KEY_PREFIX = 'ez_spi'; |
||
23 | |||
24 | /** |
||
25 | * @var \Stash\Interfaces\PoolInterface |
||
26 | */ |
||
27 | protected $cachePool; |
||
28 | |||
29 | /** |
||
30 | * Constructs the cache service decorator. |
||
31 | * |
||
32 | * @param \Stash\Interfaces\PoolInterface $cachePool |
||
33 | */ |
||
34 | public function __construct(PoolInterface $cachePool) |
||
38 | |||
39 | /** |
||
40 | * Prepend key with prefix and support array format Stash supported before. |
||
41 | * |
||
42 | * {@see \Psr\Cache\CacheItemPoolInterface} |
||
43 | * |
||
44 | * @internal param array|string $key , $key, $key... |
||
45 | * |
||
46 | * @return \Stash\Interfaces\ItemInterface |
||
47 | */ |
||
48 | public function getItem() |
||
49 | { |
||
50 | $args = func_get_args(); |
||
51 | |||
52 | if (empty($args)) { |
||
53 | return $this->cachePool->getItem(self::SPI_CACHE_KEY_PREFIX); |
||
54 | } |
||
55 | |||
56 | // Upstream seems to no longer support array, so we flatten it |
||
57 | if (!isset($args[1]) && is_array($args[0])) { |
||
58 | $key = implode('/', array_map([$this, 'washKey'], $args[0])); |
||
59 | } else { |
||
60 | $key = '' . implode('/', array_map([$this, 'washKey'], $args)); |
||
61 | } |
||
62 | |||
63 | $key = $key === '' ? self::SPI_CACHE_KEY_PREFIX : self::SPI_CACHE_KEY_PREFIX . '/' . $key; |
||
64 | |||
65 | return $this->cachePool->getItem($key); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Prepend keys with prefix. |
||
70 | * |
||
71 | * {@see \Psr\Cache\CacheItemPoolInterface} |
||
72 | * |
||
73 | * @param array $keys |
||
74 | * @return \Stash\Interfaces\ItemInterface[] |
||
75 | */ |
||
76 | public function getItems(array $keys = array()) |
||
90 | |||
91 | /** |
||
92 | * Remove slashes from start and end of keys, and for content replace it with _ to avoid issues for Stash. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @return string |
||
96 | */ |
||
97 | private function washKey($key) |
||
101 | |||
102 | /** |
||
103 | * Clears the cache for the key, or if none is specified clears the entire cache. The key can be either |
||
104 | * a series of string arguments, or an array. |
||
105 | * |
||
106 | * @internal param array|null|string $key , $key, $key... |
||
107 | */ |
||
108 | public function clear() |
||
114 | } |
||
115 |