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;
13 require_once 'include/dba.php';
16 * @brief Management of user configuration storage
18 * Please do not store booleans - convert to 0/1 integer values
19 * The PConfig::get() functions return boolean false for keys that are unset,
20 * and this could lead to subtle bugs.
22 class PConfig extends BaseObject
25 * @var Friendica\Core\Config\IPConfigAdapter
27 private static $adapter = null;
29 public static function init($uid)
31 // Database isn't ready or populated yet
32 if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) {
36 if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
37 self::$adapter = new Config\PreloadPConfigAdapter($uid);
39 self::$adapter = new Config\JITPConfigAdapter($uid);
44 * @brief Loads all configuration values of a user's config family into a cached storage.
46 * All configuration values of the given user are stored in global cache
47 * which is available under the global variable $a->config[$uid].
49 * @param string $uid The user_id
50 * @param string $family The category of the configuration value
54 public static function load($uid, $family)
56 // Database isn't ready or populated yet
57 if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) {
61 if (empty(self::$adapter)) {
65 self::$adapter->load($uid, $family);
69 * @brief Get a particular user's config variable given the category name
70 * ($family) and a key.
72 * Get a particular user's config value from the given category ($family)
73 * and the $key from a cached storage in $a->config[$uid].
75 * @param string $uid The user_id
76 * @param string $family The category of the configuration value
77 * @param string $key The configuration key to query
78 * @param mixed $default_value optional, The value to return if key is not set (default: null)
79 * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
81 * @return mixed Stored value or null if it does not exist
83 public static function get($uid, $family, $key, $default_value = null, $refresh = false)
85 // Database isn't ready or populated yet
86 if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) {
90 if (empty(self::$adapter)) {
94 return self::$adapter->get($uid, $family, $key, $default_value, $refresh);
98 * @brief Sets a configuration value for a user
100 * Stores a config value ($value) in the category ($family) under the key ($key)
101 * for the user_id $uid.
103 * @note Please do not store booleans - convert to 0/1 integer values!
105 * @param string $uid The user_id
106 * @param string $family The category of the configuration value
107 * @param string $key The configuration key to set
108 * @param string $value The value to store
110 * @return bool Operation success
112 public static function set($uid, $family, $key, $value)
114 // Database isn't ready or populated yet
115 if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) {
119 if (empty(self::$adapter)) {
123 return self::$adapter->set($uid, $family, $key, $value);
127 * @brief Deletes the given key from the users's configuration.
129 * Removes the configured value from the stored cache in $a->config[$uid]
130 * and removes it from the database.
132 * @param string $uid The user_id
133 * @param string $family The category of the configuration value
134 * @param string $key The configuration key to delete
138 public static function delete($uid, $family, $key)
140 // Database isn't ready or populated yet
141 if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) {
145 if (empty(self::$adapter)) {
149 return self::$adapter->delete($uid, $family, $key);