Version 1
[yaffs-website] / vendor / consolidation / annotated-command / tests / src / InMemoryCacheStore.php
1 <?php
2 namespace Consolidation\TestUtils;
3
4 use Consolidation\AnnotatedCommand\Cache\SimpleCacheInterface;
5
6 /**
7  * A simple in-memory cache for testing
8  */
9 class InMemoryCacheStore implements SimpleCacheInterface
10 {
11     protected $cache;
12
13     public function __construct()
14     {
15         $this->cache = [];
16     }
17
18     /**
19      * Test for an entry from the cache
20      * @param string $key
21      * @return boolean
22      */
23     public function has($key)
24     {
25         return array_key_exists($key, $this->cache);
26     }
27
28     /**
29      * Get an entry from the cache
30      * @param string $key
31      * @return array
32      */
33     public function get($key)
34     {
35         if (!$this->has($key)) {
36             return [];
37         }
38         return $this->cache[$key];
39     }
40
41     /**
42      * Store an entry in the cache
43      * @param string $key
44      * @param array $data
45      */
46     public function set($key, $data)
47     {
48         $this->cache[$key] = $data;
49     }
50 }