1 | <?php |
||
24 | class CacheAdapterFactory |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $cacheDir; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $callbacks = []; |
||
35 | |||
36 | 85 | public function __construct($cacheDir = null) |
|
37 | { |
||
38 | 85 | $this->cacheDir = !is_null($cacheDir) ? $cacheDir : realpath(__DIR__ . '/../..'); |
|
39 | 85 | $this->registerCallback( |
|
40 | 85 | function ($cache) { |
|
41 | 5 | if ($cache instanceof Cache) { |
|
42 | 1 | return new DoctrineCachePool($cache); |
|
43 | } |
||
44 | 4 | return null; |
|
45 | 85 | } |
|
46 | ) |
||
47 | 85 | ->registerCallback( |
|
48 | 85 | function ($cache) { |
|
49 | 4 | if ($cache instanceof \Redis) { |
|
50 | 1 | return new RedisCachePool($cache); |
|
51 | } |
||
52 | 3 | return null; |
|
53 | 85 | } |
|
54 | ); |
||
55 | 85 | } |
|
56 | |||
57 | /** |
||
58 | * registers a callback to resolve a cache adapter interface |
||
59 | * |
||
60 | * @param callable $callback |
||
61 | * @return $this |
||
62 | */ |
||
63 | 85 | public function registerCallback(callable $callback) |
|
69 | |||
70 | /** |
||
71 | * returns the cache adapter interface for the application cache |
||
72 | * |
||
73 | * @param $cache |
||
74 | * @return CacheItemPoolInterface|CacheInterface |
||
75 | * @throws \InvalidArgumentException |
||
76 | */ |
||
77 | 85 | public function get($cache = null) |
|
102 | |||
103 | /** |
||
104 | * creates a default cache adapter if no cache has been provided |
||
105 | * |
||
106 | * @return CacheItemPoolInterface|null |
||
107 | */ |
||
108 | 35 | protected function getDefaultCache() |
|
122 | } |
||
123 |