add doxygen to config functions

This commit is contained in:
rabuzarus 2016-06-06 10:01:14 +02:00
parent ec89274cd8
commit 5f081cc47b

View file

@ -1,8 +1,9 @@
<?php <?php
/** /**
* * @file include/config.php
* Arbitrary configuration storage *
* @brief Arbitrary configuration storage
* Note: * Note:
* Please do not store booleans - convert to 0/1 integer values * Please do not store booleans - convert to 0/1 integer values
* The get_?config() functions return boolean false for keys that are unset, * The get_?config() functions return boolean false for keys that are unset,
@ -12,10 +13,16 @@
* configurations need to be fixed as of 10/08/2011. * configurations need to be fixed as of 10/08/2011.
*/ */
/**
// retrieve a "family" of config variables from database to cached storage * @brief Loads all configuration values of family into a cached storage.
*
if(! function_exists('load_config')) { * All configuration values of the system are stored in global cache
* which is available under the global variable $a->config
*
* @param string $family
* The category of the configuration value
* @return void
*/
function load_config($family) { function load_config($family) {
global $a; global $a;
@ -33,17 +40,27 @@ function load_config($family) {
// Negative caching // Negative caching
$a->config[$family] = "!<unset>!"; $a->config[$family] = "!<unset>!";
} }
}} }
// get a particular config variable given the family name /**
// and key. Returns false if not set. * @brief Get a particular user's config variable given the category name
// $instore is only used by the set_config function * ($family) and a key.
// to determine if the key already exists in the DB *
// If a key is found in the DB but doesn't exist in * Get a particular config value from the given category ($family)
// local config cache, pull it into the cache so we don't have * and the $key from a cached storage in $a->config[$uid].
// to hit the DB again for this item. * $instore is only used by the set_config function
* to determine if the key already exists in the DB
if(! function_exists('get_config')) { * If a key is found in the DB but doesn't exist in
* local config cache, pull it into the cache so we don't have
* to hit the DB again for this item.
*
* @param string $family
* The category of the configuration value
* @param string $key
* The configuration key to query
* @param boolean $instore Determines if the key already exists in the DB
* @return mixed Stored value or false if it does not exist
*/
function get_config($family, $key, $instore = false) { function get_config($family, $key, $instore = false) {
global $a; global $a;
@ -114,13 +131,24 @@ function get_config($family, $key, $instore = false) {
xcache_set($family."|".$key, '!<unset>!', 600);*/ xcache_set($family."|".$key, '!<unset>!', 600);*/
} }
return false; return false;
}} }
// Store a config value ($value) in the category ($family) /**
// under the key ($key) * @brief Sets a configuration value for system config
// Return the value, or false if the database update failed *
* Stores a config value ($value) in the category ($family) under the key ($key)
if(! function_exists('set_config')) { * for the user_id $uid.
*
* Note: Please do not store booleans - convert to 0/1 integer values!
*
* @param string $family
* The category of the configuration value
* @param string $key
* The configuration key to set
* @param string $value
* The value to store
* @return mixed Stored $value or false if the database update failed
*/
function set_config($family,$key,$value) { function set_config($family,$key,$value) {
global $a; global $a;
@ -164,10 +192,50 @@ function set_config($family,$key,$value) {
if($ret) if($ret)
return $value; return $value;
return $ret; return $ret;
}} }
/**
* @brief Deletes the given key from the system configuration.
*
* Removes the configured value from the stored cache in $a->config
* and removes it from the database.
*
* @param string $family
* The category of the configuration value
* @param string $key
* The configuration key to delete
* @return mixed
*/
function del_config($family,$key) {
if(! function_exists('load_pconfig')) { global $a;
if(x($a->config[$family],$key))
unset($a->config[$family][$key]);
$ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'",
dbesc($family),
dbesc($key)
);
// If APC is enabled then delete the data from there, else try XCache
/*if (function_exists("apc_delete"))
apc_delete($family."|".$key);
elseif (function_exists("xcache_unset"))
xcache_unset($family."|".$key);*/
return $ret;
}
/**
* @brief Loads all configuration values of a user's config family into a cached storage.
*
* All configuration values of the given user are stored in global cache
* which is available under the global variable $a->config[$uid].
*
* @param string $uid
* The user_id
* @param string $family
* The category of the configuration value
* @return void
*/
function load_pconfig($uid,$family) { function load_pconfig($uid,$family) {
global $a; global $a;
$r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d", $r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d",
@ -183,11 +251,25 @@ function load_pconfig($uid,$family) {
// Negative caching // Negative caching
$a->config[$uid][$family] = "!<unset>!"; $a->config[$uid][$family] = "!<unset>!";
} }
}} }
/**
* @brief Get a particular user's config variable given the category name
if(! function_exists('get_pconfig')) { * ($family) and a key.
*
* Get a particular user's config value from the given category ($family)
* and the $key from a cached storage in $a->config[$uid].
*
* @param string $uid
* The user_id
* @param string $family
* The category of the configuration value
* @param string $key
* The configuration key to query
* @param boolean $instore
* Determines if the key already exists in the DB
* @return mixed Stored value or false if it does not exist
*/
function get_pconfig($uid,$family, $key, $instore = false) { function get_pconfig($uid,$family, $key, $instore = false) {
global $a; global $a;
@ -259,33 +341,26 @@ function get_pconfig($uid,$family, $key, $instore = false) {
xcache_set($uid."|".$family."|".$key, '!<unset>!', 600);*/ xcache_set($uid."|".$family."|".$key, '!<unset>!', 600);*/
} }
return false; return false;
}} }
if(! function_exists('del_config')) { /**
function del_config($family,$key) { * @brief Sets a configuration value for a user
*
global $a; * Stores a config value ($value) in the category ($family) under the key ($key)
if(x($a->config[$family],$key)) * for the user_id $uid.
unset($a->config[$family][$key]); *
$ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s'", * @note Please do not store booleans - convert to 0/1 integer values!
dbesc($family), *
dbesc($key) * @param string $uid
); * The user_id
// If APC is enabled then delete the data from there, else try XCache * @param string $family
/*if (function_exists("apc_delete")) * The category of the configuration value
apc_delete($family."|".$key); * @param string $key
elseif (function_exists("xcache_unset")) * The configuration key to set
xcache_unset($family."|".$key);*/ * @param string $value
* The value to store
return $ret; * @return mixed Stored $value or false
}} */
// Same as above functions except these are for personal config storage and take an
// additional $uid argument.
if(! function_exists('set_pconfig')) {
function set_pconfig($uid,$family,$key,$value) { function set_pconfig($uid,$family,$key,$value) {
global $a; global $a;
@ -324,9 +399,21 @@ function set_pconfig($uid,$family,$key,$value) {
if($ret) if($ret)
return $value; return $value;
return $ret; return $ret;
}} }
if(! function_exists('del_pconfig')) { /**
* @brief Deletes the given key from the users's configuration.
*
* Removes the configured value from the stored cache in $a->config[$uid]
* and removes it from the database.
*
* @param string $uid The user_id
* @param string $family
* The category of the configuration value
* @param string $key
* The configuration key to delete
* @return mixed
*/
function del_pconfig($uid,$family,$key) { function del_pconfig($uid,$family,$key) {
global $a; global $a;
@ -338,4 +425,4 @@ function del_pconfig($uid,$family,$key) {
dbesc($key) dbesc($key)
); );
return $ret; return $ret;
}} }