12
12
*/
13
13
class Cache
14
14
{
15
+ private $ drivers = [];
16
+
15
17
/**
16
18
* Contains all cache instances
17
19
*
@@ -28,25 +30,23 @@ class Cache
28
30
*/
29
31
public function __construct ($ drivers )
30
32
{
31
- foreach ($ drivers ['drivers ' ] as $ name => $ driver ) {
32
- $ this ->createInstance ($ name , CacheManager::getInstance ($ driver ['type ' ], $ driver ['parameters ' ]));
33
- }
33
+ $ this ->drivers = (array ) $ drivers [ 'drivers ' ];
34
34
}
35
35
36
36
/**
37
37
* Set a new cache instance
38
38
*
39
- * @param string $name
39
+ * @param string $name
40
40
* @param ExtendedCacheItemPoolInterface $instance
41
41
*
42
42
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException
43
43
*/
44
44
public function createInstance ($ name , ExtendedCacheItemPoolInterface $ instance )
45
45
{
46
- if (array_key_exists ($ name , $ this ->cacheInstances ) && $ this ->cacheInstances [$ name ] instanceof ExtendedCacheItemPoolInterface) {
46
+ if (array_key_exists ($ name , $ this ->cacheInstances ) && $ this ->cacheInstances [ $ name ] instanceof ExtendedCacheItemPoolInterface) {
47
47
throw new phpFastCacheDriverException ("Cache instance ' {$ name }' already exists " );
48
48
}
49
- $ this ->cacheInstances [$ name ] = $ instance ;
49
+ $ this ->cacheInstances [ $ name ] = $ instance ;
50
50
}
51
51
52
52
/**
@@ -61,13 +61,17 @@ public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
61
61
public function get ($ name )
62
62
{
63
63
if (!array_key_exists ($ name , $ this ->cacheInstances )) {
64
- throw new phpFastCacheDriverException ("Cache instance ' {$ name }' not exists " );
65
- }
66
- if (!$ this ->cacheInstances [$ name ] instanceof ExtendedCacheItemPoolInterface) {
67
- throw new phpFastCacheDriverException ("Cache instance ' {$ name }' already instanciated " );
64
+ if (array_key_exists ($ name , $ this ->drivers )) {
65
+ $ this ->createInstance ($ name , CacheManager::getInstance ($ this ->drivers [ $ name ][ 'type ' ], $ this ->drivers [ $ name ][ 'parameters ' ]));
66
+ if (!$ this ->cacheInstances [ $ name ] instanceof ExtendedCacheItemPoolInterface) {
67
+ throw new phpFastCacheDriverException ("Cache instance ' {$ name }' does not implements ExtendedCacheItemPoolInterface " );
68
+ }
69
+ } else {
70
+ throw new phpFastCacheDriverException ("Cache instance ' {$ name }' not exists, check your config.yml " );
71
+ }
68
72
}
69
73
70
- return $ this ->cacheInstances [$ name ];
74
+ return $ this ->cacheInstances [ $ name ];
71
75
}
72
76
73
77
/**
0 commit comments