From 136ae34245afeb5a8acefc3b48cde7a7486763bd Mon Sep 17 00:00:00 2001 From: Fabrixxm Date: Fri, 10 Jun 2016 12:00:34 +0200 Subject: [PATCH] Add `$default_value` parameter to `Config::get()` and `PConfig::get()` --- include/Core/Config.php | 14 ++++++++------ include/Core/PConfig.php | 14 ++++++++------ include/config.php | 10 ++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index bbae746b44..b5d80c82e0 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -64,11 +64,13 @@ class Config { * The category of the configuration value * @param string $key * The configuration key to query - * @param boolean $refresh - * If true the config is loaded from the db and not from the cache + * @param mixed $default_value optional + * The value to return if key is not set (default: null) + * @param boolean $refresh optional + * If true the config is loaded from the db and not from the cache (default: false) * @return mixed Stored value or null if it does not exist */ - public static function get($family, $key, $refresh = false) { + public static function get($family, $key, $default_value=null, $refresh = false) { global $a; @@ -76,13 +78,13 @@ class Config { // Looking if the whole family isn't set if(isset($a->config[$family])) { if($a->config[$family] === '!!') { - return null; + return $default_value; } } if(isset($a->config[$family][$key])) { if($a->config[$family][$key] === '!!') { - return null; + return $default_value; } return $a->config[$family][$key]; } @@ -137,7 +139,7 @@ class Config { elseif (function_exists("xcache_set")) xcache_set($family."|".$key, '!!', 600);*/ } - return null; + return $default_value; } /** diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 9ca608e76e..09c3c2a0b2 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -57,11 +57,13 @@ class PConfig { * The category of the configuration value * @param string $key * The configuration key to query - * @param boolean $refresh - * If true the config is loaded from the db and not from the cache + * @param mixed $default_value optional + * The value to return if key is not set (default: null) + * @param boolean $refresh optional + * If true the config is loaded from the db and not from the cache (default: false) * @return mixed Stored value or null if it does not exist */ - public static function get($uid, $family, $key, $refresh = false) { + public static function get($uid, $family, $key, $default_value = null, $refresh = false) { global $a; @@ -69,13 +71,13 @@ class PConfig { // Looking if the whole family isn't set if(isset($a->config[$uid][$family])) { if($a->config[$uid][$family] === '!!') { - return null; + return $default_value; } } if(isset($a->config[$uid][$family][$key])) { if($a->config[$uid][$family][$key] === '!!') { - return null; + return $default_value; } return $a->config[$uid][$family][$key]; } @@ -131,7 +133,7 @@ class PConfig { elseif (function_exists("xcache_set")) xcache_set($uid."|".$family."|".$key, '!!', 600);*/ } - return null; + return $default_value; } /** diff --git a/include/config.php b/include/config.php index c96651cdc6..c51db4ec7b 100644 --- a/include/config.php +++ b/include/config.php @@ -43,10 +43,7 @@ function load_config($family) { * @return mixed Stored value or false if it does not exist */ function get_config($family, $key, $refresh = false) { - $v = Config::get($family, $key, $refresh); - if(is_null($v)) - $v = false; - + $v = Config::get($family, $key, false, $refresh); return $v; } @@ -114,10 +111,7 @@ function load_pconfig($uid,$family) { * @return mixed Stored value or false if it does not exist */ function get_pconfig($uid, $family, $key, $refresh = false) { - $v = PConfig::get($uid, $family, $key, $refresh); - if(is_null($v)) - $v = false; - + $v = PConfig::get($uid, $family, $key, false, $refresh); return $v; }