Skip to content

Commit 2834f46

Browse files
committed
Deprecated CacheManager::setup() in favor of CacheManager::setDefaultConfig()
1 parent 201dd6d commit 2834f46

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

examples/decrement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use phpFastCache\Core\phpFastCache;
2323

2424
// Setup File Path on your config files
25-
CacheManager::setup([
25+
CacheManager::setDefaultConfig([
2626
"path" => '/var/www/phpfastcache.dev.geolim4.com/geolim4/tmp', // or in windows "C:/tmp/"
2727
]);
2828

examples/files.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use phpFastCache\Core\phpFastCache;
2222

2323
// Setup File Path on your config files
24-
CacheManager::setup([
24+
CacheManager::setDefaultConfig([
2525
"path" => '/var/www/phpfastcache.dev.geolim4.com/geolim4/tmp', // or in windows "C:/tmp/"
2626
]);
2727

examples/increment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use phpFastCache\Core\phpFastCache;
2222

2323
// Setup File Path on your config files
24-
CacheManager::setup([
24+
CacheManager::setDefaultConfig([
2525
"path" => '/var/www/phpfastcache.dev.geolim4.com/geolim4/tmp', // or in windows "C:/tmp/"
2626
]);
2727

examples/sqlite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use phpFastCache\Core\phpFastCache;
2323

2424
// Setup File Path on your config files
25-
CacheManager::setup([
25+
CacheManager::setDefaultConfig([
2626
"path" => '/var/www/phpfastcache.dev.geolim4.com/geolim4/tmp', // or in windows "C:/tmp/"
2727
]);
2828

src/phpFastCache/CacheManager.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class CacheManager
5151
/**
5252
* @var array
5353
*/
54-
public static $config = [
54+
protected static $config = [
5555
'default_chmod' => 0777, // 0777 recommended
5656
'fallback' => 'files', //Fall back when old driver is not support
57-
'securityKey' => 'auto',
58-
'htaccess' => true,
57+
'securityKey' => 'auto',// The securityKey that will be used to create sub-directory
58+
'htaccess' => true,// Auto-generate .htaccess if tit is missing
5959
'path' => '',// if not set will be the value of sys_get_temp_dir()
6060
"limited_memory_each_object" => 4096, // maximum size (bytes) of object store in memory
6161
"compress_data" => false, // compress stored data, if the backend supports it
@@ -143,6 +143,7 @@ public static function clearInstances()
143143
unset($instance);
144144
}
145145

146+
gc_collect_cycles();
146147
return !count(self::$instances);
147148
}
148149

@@ -165,16 +166,37 @@ public static function setNamespacePath($path)
165166
/**
166167
* @param $name
167168
* @param string $value
169+
* @deprecated Method "setup" is deprecated and will be removed in 5.1. Use method "setDefaultConfig" instead.
168170
*/
169171
public static function setup($name, $value = '')
172+
{
173+
trigger_error('Method "setup" is deprecated and will be removed in 5.1. Use method "setDefaultConfig" instead.');
174+
self::setDefaultConfig($name, $value);
175+
}
176+
177+
/**
178+
* @param $name string|array
179+
* @param mixed $value
180+
*/
181+
public static function setDefaultConfig($name, $value = null)
170182
{
171183
if (is_array($name)) {
172184
self::$config = array_merge(self::$config, $name);
173-
} else {
185+
} else if (is_string($name)){
174186
self::$config[ $name ] = $value;
187+
}else{
188+
throw new \InvalidArgumentException('Invalid variable type: $name');
175189
}
176190
}
177191

192+
/**
193+
* @return array
194+
*/
195+
public function getDefaultConfig()
196+
{
197+
return self::$config;
198+
}
199+
178200
/**
179201
* @return array
180202
*/

0 commit comments

Comments
 (0)