3 * User Configuration Class
5 * @file include/Core/PConfig.php
7 * @brief Contains the class with methods for user configuration
9 namespace Friendica\Core;
12 use Friendica\BaseObject;
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)
34 // Database isn't ready or populated yet
35 if (!$a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
39 if ($a->getConfigValue('system', 'config_adapter') == 'preload') {
40 self::$adapter = new Config\PreloadPConfigAdapter($uid);
42 self::$adapter = new Config\JITPConfigAdapter($uid);
47 * @brief Loads all configuration values of a user's config family into a cached storage.
49 * All configuration values of the given user are stored in global cache
50 * which is available under the global variable $a->config[$uid].
52 * @param string $uid The user_id
53 * @param string $family The category of the configuration value
57 public static function load($uid, $family)
59 // Database isn't ready or populated yet
60 if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
64 if (empty(self::$adapter)) {
68 self::$adapter->load($uid, $family);
72 * @brief Get a particular user's config variable given the category name
73 * ($family) and a key.
75 * Get a particular user's config value from the given category ($family)
76 * and the $key from a cached storage in $a->config[$uid].
78 * @param string $uid The user_id
79 * @param string $family The category of the configuration value
80 * @param string $key The configuration key to query
81 * @param mixed $default_value optional, The value to return if key is not set (default: null)
82 * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
84 * @return mixed Stored value or null if it does not exist
86 public static function get($uid, $family, $key, $default_value = null, $refresh = false)
88 // Database isn't ready or populated yet
89 if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
93 if (empty(self::$adapter)) {
97 return self::$adapter->get($uid, $family, $key, $default_value, $refresh);
101 * @brief Sets a configuration value for a user
103 * Stores a config value ($value) in the category ($family) under the key ($key)
104 * for the user_id $uid.
106 * @note Please do not store booleans - convert to 0/1 integer values!
108 * @param string $uid The user_id
109 * @param string $family The category of the configuration value
110 * @param string $key The configuration key to set
111 * @param string $value The value to store
113 * @return bool Operation success
115 public static function set($uid, $family, $key, $value)
117 // Database isn't ready or populated yet
118 if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
122 if (empty(self::$adapter)) {
126 return self::$adapter->set($uid, $family, $key, $value);
130 * @brief Deletes the given key from the users's configuration.
132 * Removes the configured value from the stored cache in $a->config[$uid]
133 * and removes it from the database.
135 * @param string $uid The user_id
136 * @param string $family The category of the configuration value
137 * @param string $key The configuration key to delete
141 public static function delete($uid, $family, $key)
143 // Database isn't ready or populated yet
144 if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
148 if (empty(self::$adapter)) {
152 return self::$adapter->delete($uid, $family, $key);