-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCachePoolAwareTrait.php
51 lines (44 loc) · 1.08 KB
/
CachePoolAwareTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Charcoal\Cache;
use RuntimeException;
// From PSR-6
use Psr\Cache\CacheItemPoolInterface;
/**
* The Cache Aware Trait provides the methods necessary for an object
* to use a "Cache" service.
*/
trait CachePoolAwareTrait
{
/**
* Store the PSR-6 caching service.
*
* @var CacheItemPoolInterface
*/
private $cachePool;
/**
* Set the cache pool manager.
*
* @param CacheItemPoolInterface $cache A PSR-6 compliant cache pool instance.
* @return void
*/
protected function setCachePool(CacheItemPoolInterface $cache)
{
$this->cachePool = $cache;
}
/**
* Retrieve the cache service.
*
* @throws RuntimeException If the cache service was not previously set.
* @return CacheItemPoolInterface
*/
protected function cachePool()
{
if ($this->cachePool === null) {
throw new RuntimeException(sprintf(
'Cache Pool is not defined for "%s"',
get_class($this)
));
}
return $this->cachePool;
}
}