3 * User Configuration Class
5 * @file include/Core/PConfig.php
7 * @brief Contains the class with methods for user configuration
9 namespace Friendica\Core;
11 use Friendica\BaseObject;
12 use Friendica\Core\Config;
14 require_once 'include/dba.php';
17 * @brief Management of user configuration storage
19 * Please do not store booleans - convert to 0/1 integer values
20 * The PConfig::get() functions return boolean false for keys that are unset,
21 * and this could lead to subtle bugs.
23 class PConfig extends BaseObject
26 * @var Friendica\Core\Config\IPConfigAdapter
28 private static $adapter = null;
30 public static function init($uid)
32 if (Config::get('system', 'config_adapter') == 'preload') {
33 self::$adapter = new Config\PreloadPConfigAdapter($uid);
35 self::$adapter = new Config\JITPConfigAdapter($uid);
40 * @brief Loads all configuration values of a user's config family into a cached storage.
42 * All configuration values of the given user are stored in global cache
43 * which is available under the global variable $a->config[$uid].
45 * @param string $uid The user_id
46 * @param string $family The category of the configuration value
50 public static function load($uid, $family)
52 if (empty(self::$adapter)) {
56 self::$adapter->load($uid, $family);
60 * @brief Get a particular user's config variable given the category name
61 * ($family) and a key.
63 * Get a particular user's config value from the given category ($family)
64 * and the $key from a cached storage in $a->config[$uid].
66 * @param string $uid The user_id
67 * @param string $family The category of the configuration value
68 * @param string $key The configuration key to query
69 * @param mixed $default_value optional, The value to return if key is not set (default: null)
70 * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
72 * @return mixed Stored value or null if it does not exist
74 public static function get($uid, $family, $key, $default_value = null, $refresh = false)
76 if (empty(self::$adapter)) {
80 return self::$adapter->get($uid, $family, $key, $default_value, $refresh);
84 * @brief Sets a configuration value for a user
86 * Stores a config value ($value) in the category ($family) under the key ($key)
87 * for the user_id $uid.
89 * @note Please do not store booleans - convert to 0/1 integer values!
91 * @param string $uid The user_id
92 * @param string $family The category of the configuration value
93 * @param string $key The configuration key to set
94 * @param string $value The value to store
96 * @return mixed Stored $value or false
98 public static function set($uid, $family, $key, $value)
100 if (empty(self::$adapter)) {
104 return self::$adapter->set($uid, $family, $key, $value);
108 * @brief Deletes the given key from the users's configuration.
110 * Removes the configured value from the stored cache in $a->config[$uid]
111 * and removes it from the database.
113 * @param string $uid The user_id
114 * @param string $family The category of the configuration value
115 * @param string $key The configuration key to delete
119 public static function delete($uid, $family, $key)
121 if (empty(self::$adapter)) {
125 return self::$adapter->delete($uid, $family, $key);