From f2e79e976d06689a9f7272e70441b3d222984175 Mon Sep 17 00:00:00 2001 From: Fabrixxm Date: Fri, 10 Jun 2016 11:50:52 +0200 Subject: [PATCH 1/3] set include/ folder base for 'Friendica' PSR4 namespace --- include/autoloader/autoload_psr4.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/autoloader/autoload_psr4.php b/include/autoloader/autoload_psr4.php index fe93afea21..d000ea28f6 100644 --- a/include/autoloader/autoload_psr4.php +++ b/include/autoloader/autoload_psr4.php @@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(dirname(__FILE__)))."/library"; $baseDir = dirname($vendorDir); return array( + 'Friendica\\' => array($baseDir . '/include'), ); From 6c346b1ab64fefebe61be3ddf36cf48eccd52d69 Mon Sep 17 00:00:00 2001 From: Fabrixxm Date: Fri, 10 Jun 2016 11:52:01 +0200 Subject: [PATCH 2/3] Move `Config` and `PConfig` classes in `\Friendica\Core namespace` --- include/{ => Core}/Config.php | 4 ++-- include/{ => Core}/PConfig.php | 4 ++-- include/config.php | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) rename include/{ => Core}/Config.php (99%) rename include/{ => Core}/PConfig.php (99%) diff --git a/include/Config.php b/include/Core/Config.php similarity index 99% rename from include/Config.php rename to include/Core/Config.php index e08a7de747..bbae746b44 100644 --- a/include/Config.php +++ b/include/Core/Config.php @@ -1,7 +1,7 @@ Date: Fri, 10 Jun 2016 12:00:34 +0200 Subject: [PATCH 3/3] 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; }