Merge pull request #2585 from fabrixxm/update_config_classes
Update config classes
This commit is contained in:
commit
710822dca7
4 changed files with 26 additions and 28 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Friendica\Core;
|
||||||
/**
|
/**
|
||||||
* @file include/Config.php
|
* @file include/Core/Config.php
|
||||||
*
|
*
|
||||||
* @brief Contains the class with methods for system configuration
|
* @brief Contains the class with methods for system configuration
|
||||||
*/
|
*/
|
||||||
|
@ -64,11 +64,13 @@ class Config {
|
||||||
* The category of the configuration value
|
* The category of the configuration value
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* The configuration key to query
|
* The configuration key to query
|
||||||
* @param boolean $refresh
|
* @param mixed $default_value optional
|
||||||
* If true the config is loaded from the db and not from the cache
|
* 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
|
* @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;
|
global $a;
|
||||||
|
|
||||||
|
@ -76,13 +78,13 @@ class Config {
|
||||||
// Looking if the whole family isn't set
|
// Looking if the whole family isn't set
|
||||||
if(isset($a->config[$family])) {
|
if(isset($a->config[$family])) {
|
||||||
if($a->config[$family] === '!<unset>!') {
|
if($a->config[$family] === '!<unset>!') {
|
||||||
return null;
|
return $default_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($a->config[$family][$key])) {
|
if(isset($a->config[$family][$key])) {
|
||||||
if($a->config[$family][$key] === '!<unset>!') {
|
if($a->config[$family][$key] === '!<unset>!') {
|
||||||
return null;
|
return $default_value;
|
||||||
}
|
}
|
||||||
return $a->config[$family][$key];
|
return $a->config[$family][$key];
|
||||||
}
|
}
|
||||||
|
@ -137,7 +139,7 @@ class Config {
|
||||||
elseif (function_exists("xcache_set"))
|
elseif (function_exists("xcache_set"))
|
||||||
xcache_set($family."|".$key, '!<unset>!', 600);*/
|
xcache_set($family."|".$key, '!<unset>!', 600);*/
|
||||||
}
|
}
|
||||||
return null;
|
return $default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Friendica\Core;
|
||||||
/**
|
/**
|
||||||
* @file include/PConfig.php
|
* @file include/Core/PConfig.php
|
||||||
* @brief contains the class with methods for the management
|
* @brief contains the class with methods for the management
|
||||||
* of the user configuration
|
* of the user configuration
|
||||||
*/
|
*/
|
||||||
|
@ -57,11 +57,13 @@ class PConfig {
|
||||||
* The category of the configuration value
|
* The category of the configuration value
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* The configuration key to query
|
* The configuration key to query
|
||||||
* @param boolean $refresh
|
* @param mixed $default_value optional
|
||||||
* If true the config is loaded from the db and not from the cache
|
* 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
|
* @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;
|
global $a;
|
||||||
|
|
||||||
|
@ -69,13 +71,13 @@ class PConfig {
|
||||||
// Looking if the whole family isn't set
|
// Looking if the whole family isn't set
|
||||||
if(isset($a->config[$uid][$family])) {
|
if(isset($a->config[$uid][$family])) {
|
||||||
if($a->config[$uid][$family] === '!<unset>!') {
|
if($a->config[$uid][$family] === '!<unset>!') {
|
||||||
return null;
|
return $default_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($a->config[$uid][$family][$key])) {
|
if(isset($a->config[$uid][$family][$key])) {
|
||||||
if($a->config[$uid][$family][$key] === '!<unset>!') {
|
if($a->config[$uid][$family][$key] === '!<unset>!') {
|
||||||
return null;
|
return $default_value;
|
||||||
}
|
}
|
||||||
return $a->config[$uid][$family][$key];
|
return $a->config[$uid][$family][$key];
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,7 @@ class PConfig {
|
||||||
elseif (function_exists("xcache_set"))
|
elseif (function_exists("xcache_set"))
|
||||||
xcache_set($uid."|".$family."|".$key, '!<unset>!', 600);*/
|
xcache_set($uid."|".$family."|".$key, '!<unset>!', 600);*/
|
||||||
}
|
}
|
||||||
return null;
|
return $default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'Friendica\\' => array($baseDir . '/include'),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once("include/PConfig.php");
|
|
||||||
require_once("include/Config.php");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file include/config.php
|
* @file include/config.php
|
||||||
*
|
*
|
||||||
|
@ -16,6 +12,9 @@ require_once("include/Config.php");
|
||||||
* configurations need to be fixed as of 10/08/2011.
|
* configurations need to be fixed as of 10/08/2011.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use \Friendica\Core\Config;
|
||||||
|
use \Friendica\Core\PConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief (Deprecated) Loads all configuration values of family into a cached storage.
|
* @brief (Deprecated) Loads all configuration values of family into a cached storage.
|
||||||
*
|
*
|
||||||
|
@ -44,10 +43,7 @@ function load_config($family) {
|
||||||
* @return mixed Stored value or false if it does not exist
|
* @return mixed Stored value or false if it does not exist
|
||||||
*/
|
*/
|
||||||
function get_config($family, $key, $refresh = false) {
|
function get_config($family, $key, $refresh = false) {
|
||||||
$v = Config::get($family, $key, $refresh);
|
$v = Config::get($family, $key, false, $refresh);
|
||||||
if(is_null($v))
|
|
||||||
$v = false;
|
|
||||||
|
|
||||||
return $v;
|
return $v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,10 +111,7 @@ function load_pconfig($uid,$family) {
|
||||||
* @return mixed Stored value or false if it does not exist
|
* @return mixed Stored value or false if it does not exist
|
||||||
*/
|
*/
|
||||||
function get_pconfig($uid, $family, $key, $refresh = false) {
|
function get_pconfig($uid, $family, $key, $refresh = false) {
|
||||||
$v = PConfig::get($uid, $family, $key, $refresh);
|
$v = PConfig::get($uid, $family, $key, false, $refresh);
|
||||||
if(is_null($v))
|
|
||||||
$v = false;
|
|
||||||
|
|
||||||
return $v;
|
return $v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue