]> git.mxchange.org Git - friendica.git/commitdiff
Add `$default_value` parameter to `Config::get()` and `PConfig::get()`
authorFabrixxm <fabrix.xm@gmail.com>
Fri, 10 Jun 2016 10:00:34 +0000 (12:00 +0200)
committerFabrixxm <fabrix.xm@gmail.com>
Fri, 10 Jun 2016 10:00:34 +0000 (12:00 +0200)
include/Core/Config.php
include/Core/PConfig.php
include/config.php

index bbae746b44dae2f3fffa457aab61988e819fc802..b5d80c82e0331449a886ab097e0a391801d3cd0b 100644 (file)
@@ -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] === '!<unset>!') {
-                                       return null;
+                                       return $default_value;
                                }
                        }
 
                        if(isset($a->config[$family][$key])) {
                                if($a->config[$family][$key] === '!<unset>!') {
-                                       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, '!<unset>!', 600);*/
                }
-               return null;
+               return $default_value;
        }
 
        /**
index 9ca608e76ec5f04a2072f8774d584e1a6302e818..09c3c2a0b22311f070b05c6e3723c4954602b00f 100644 (file)
@@ -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] === '!<unset>!') {
-                                       return null;
+                                       return $default_value;
                                }
                        }
 
                        if(isset($a->config[$uid][$family][$key])) {
                                if($a->config[$uid][$family][$key] === '!<unset>!') {
-                                       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, '!<unset>!', 600);*/
                }
-               return null;
+               return $default_value;
        }
 
        /**
index c96651cdc64006bba7b9078b9fec1f89f86f97a1..c51db4ec7b1f7fc9f550bdf3818014553a5e9ec1 100644 (file)
@@ -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;
 }