Total Complexity | 8 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
23 | trait InteractsWithCache |
||
24 | { |
||
25 | /** |
||
26 | * @var \Psr\SimpleCache\CacheInterface |
||
27 | */ |
||
28 | protected $cache; |
||
29 | |||
30 | /** |
||
31 | * Get cache instance. |
||
32 | * |
||
33 | * @return \Psr\SimpleCache\CacheInterface |
||
34 | */ |
||
35 | public function getCache() |
||
36 | { |
||
37 | if ($this->cache) { |
||
38 | return $this->cache; |
||
39 | } |
||
40 | |||
41 | if (property_exists($this, 'app') && $this->app instanceof ServiceContainer |
||
42 | && isset($this->app['cache']) && $this->app['cache'] instanceof CacheInterface) { |
||
43 | return $this->cache = $this->app['cache']; |
||
44 | } |
||
45 | |||
46 | return $this->cache = $this->createDefaultCache(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Set cache instance. |
||
51 | * |
||
52 | * @param \Psr\SimpleCache\CacheInterface $cache |
||
53 | * |
||
54 | * @return $this |
||
55 | */ |
||
56 | public function setCache(CacheInterface $cache) |
||
57 | { |
||
58 | $this->cache = $cache; |
||
59 | |||
60 | return $this; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @return \Symfony\Component\Cache\Simple\FilesystemCache |
||
65 | */ |
||
66 | protected function createDefaultCache() |
||
69 | } |
||
70 | } |
||
71 |