2727use Phpfastcache \Exceptions \PhpfastcacheUnsupportedOperationException ;
2828use Phpfastcache \Util \ClassNamespaceResolverTrait ;
2929
30- /**
31- * Class CacheManager
32- * @package phpFastCache
33- *
34- * @method static ExtendedCacheItemPoolInterface Apcu() Apcu($config = []) Return a driver "Apcu" instance
35- * @method static ExtendedCacheItemPoolInterface Cassandra() Cassandra($config = []) Return a driver "Cassandra" instance
36- * @method static ExtendedCacheItemPoolInterface Cookie() Cookie($config = []) Return a driver "Cookie" instance
37- * @method static ExtendedCacheItemPoolInterface Couchbase() Couchbase($config = []) Return a driver "Couchbase" instance
38- * @method static ExtendedCacheItemPoolInterface Couchdb() Couchdb($config = []) Return a driver "Couchdb" instance
39- * @method static ExtendedCacheItemPoolInterface Devnull() Devnull($config = []) Return a driver "Devnull" instance
40- * @method static ExtendedCacheItemPoolInterface Files() Files($config = []) Return a driver "files" instance
41- * @method static ExtendedCacheItemPoolInterface Leveldb() Leveldb($config = []) Return a driver "Leveldb" instance
42- * @method static ExtendedCacheItemPoolInterface Memcache() Memcache($config = []) Return a driver "Memcache" instance
43- * @method static ExtendedCacheItemPoolInterface Memcached() Memcached($config = []) Return a driver "Memcached" instance
44- * @method static ExtendedCacheItemPoolInterface Memstatic() Memstatic($config = []) Return a driver "Memstatic" instance
45- * @method static ExtendedCacheItemPoolInterface Mongodb() Mongodb($config = []) Return a driver "Mongodb" instance
46- * @method static ExtendedCacheItemPoolInterface Predis() Predis($config = []) Return a driver "Predis" instance
47- * @method static ExtendedCacheItemPoolInterface Redis() Redis($config = []) Return a driver "Pedis" instance
48- * @method static ExtendedCacheItemPoolInterface Sqlite() Sqlite($config = []) Return a driver "Sqlite" instance
49- * @method static ExtendedCacheItemPoolInterface Ssdb() Ssdb($config = []) Return a driver "Ssdb" instance
50- * @method static ExtendedCacheItemPoolInterface Wincache() Wincache($config = []) Return a driver "Wincache" instance
51- * @method static ExtendedCacheItemPoolInterface Zenddisk() Zenddisk($config = []) Return a driver "Zend disk cache" instance
52- * @method static ExtendedCacheItemPoolInterface Zendshm() Zendshm($config = []) Return a driver "Zend memory cache" instance
53- *
54- */
5530class CacheManager
5631{
5732 public const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers \\' ;
5833
5934 use ClassNamespaceResolverTrait;
6035
61- protected static ConfigurationOption $ config ;
36+ protected static ConfigurationOptionInterface $ config ;
6237
6338 protected static string $ namespacePath ;
6439
@@ -109,22 +84,6 @@ public static function getInstances(): array
10984 return self ::$ instances ;
11085 }
11186
112- /**
113- * @param string $name
114- * @param array $arguments
115- * @return ExtendedCacheItemPoolInterface
116- * @throws PhpfastcacheDriverCheckException
117- * @throws PhpfastcacheDriverException
118- * @throws PhpfastcacheDriverNotFoundException
119- * @throws PhpfastcacheInvalidArgumentException
120- */
121- public static function __callStatic (string $ name , array $ arguments ): ExtendedCacheItemPoolInterface
122- {
123- $ options = (\array_key_exists (0 , $ arguments ) ? $ arguments [0 ] : []);
124-
125- return self ::getInstance ($ name , $ options );
126- }
127-
12887 /**
12988 * @param string $driver
13089 * @param ConfigurationOptionInterface|null $config
@@ -133,13 +92,12 @@ public static function __callStatic(string $name, array $arguments): ExtendedCac
13392 * @throws PhpfastcacheDriverCheckException
13493 * @throws PhpfastcacheDriverException
13594 * @throws PhpfastcacheDriverNotFoundException
136- * @throws PhpfastcacheInvalidArgumentException
95+ * @throws PhpfastcacheLogicException
13796 */
13897 public static function getInstance (string $ driver , ?ConfigurationOptionInterface $ config = null , ?string $ instanceId = null ): ExtendedCacheItemPoolInterface
13998 {
14099 $ config = self ::validateConfig ($ config );
141100 $ driver = self ::standardizeDriverName ($ driver );
142-
143101 $ instanceId = $ instanceId ?: md5 ($ driver . \serialize (\array_filter ($ config ->toArray (), static fn ($ val ) => !\is_callable ($ val ))));
144102
145103 if (!isset (self ::$ instances [$ instanceId ])) {
@@ -161,18 +119,22 @@ public static function getInstance(string $driver, ?ConfigurationOptionInterface
161119 }
162120
163121 /**
164- * @param ConfigurationOption|null $config
165- * @return ConfigurationOption
122+ * @param ConfigurationOptionInterface|null $config
123+ * @return ConfigurationOptionInterface
124+ * @throws PhpfastcacheLogicException
166125 */
167- protected static function validateConfig (?ConfigurationOption $ config ): ConfigurationOption
126+ protected static function validateConfig (?ConfigurationOptionInterface $ config ): ConfigurationOptionInterface
168127 {
128+ if ($ config instanceof ConfigurationOptionInterface && $ config ->isLocked ()) {
129+ throw new PhpfastcacheLogicException ('You provided an already locked configuration, cannot continue. ' );
130+ }
169131 return $ config ?? self ::getDefaultConfig ();
170132 }
171133
172134 /**
173- * @return ConfigurationOption
135+ * @return ConfigurationOptionInterface
174136 */
175- public static function getDefaultConfig (): ConfigurationOption
137+ public static function getDefaultConfig (): ConfigurationOptionInterface
176138 {
177139 return self ::$ config ?? self ::$ config = new ConfigurationOption ();
178140 }
@@ -246,7 +208,8 @@ public static function clearInstances(): bool
246208 self ::$ instances = [];
247209
248210 \gc_collect_cycles ();
249- return !\count (self ::$ instances );
211+
212+ return true ;
250213 }
251214
252215 /**
@@ -274,9 +237,10 @@ static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInsta
274237 }
275238
276239 /**
277- * @param ConfigurationOption $config
240+ * @param ConfigurationOptionInterface $config
241+ * @throws PhpfastcacheInvalidArgumentException
278242 */
279- public static function setDefaultConfig (ConfigurationOption $ config ): void
243+ public static function setDefaultConfig (ConfigurationOptionInterface $ config ): void
280244 {
281245 if (is_subclass_of ($ config , ConfigurationOption::class)) {
282246 throw new PhpfastcacheInvalidArgumentException ('Default configuration cannot be a child class of ConfigurationOption::class ' );
0 commit comments