3 * System Configuration Class
5 * @file include/Core/Config.php
7 * @brief Contains the class with methods for system configuration
9 namespace Friendica\Core;
12 use Friendica\BaseObject;
13 use Friendica\Core\Config;
15 require_once 'include/dba.php';
18 * @brief Arbitrary system configuration storage
21 * If we ever would decide to return exactly the variable type as entered,
22 * we will have fun with the additional features. :-)
24 class Config extends BaseObject
27 * @var Friendica\Core\Config\IConfigAdapter
29 private static $adapter = null;
31 public static function init()
33 // Database isn't ready or populated yet
34 if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
38 if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
39 self::$adapter = new Config\PreloadConfigAdapter();
41 self::$adapter = new Config\JITConfigAdapter();
46 * @brief Loads all configuration values of family into a cached storage.
48 * All configuration values of the system are stored in global cache
49 * which is available under the global variable $a->config
51 * @param string $family The category of the configuration value
55 public static function load($family = "config")
57 // Database isn't ready or populated yet
58 if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
62 if (empty(self::$adapter)) {
66 self::$adapter->load($family);
70 * @brief Get a particular user's config variable given the category name
71 * ($family) and a key.
73 * Get a particular config value from the given category ($family)
74 * and the $key from a cached storage in $a->config[$uid].
75 * $instore is only used by the set_config function
76 * to determine if the key already exists in the DB
77 * If a key is found in the DB but doesn't exist in
78 * local config cache, pull it into the cache so we don't have
79 * to hit the DB again for this item.
81 * @param string $family The category of the configuration value
82 * @param string $key The configuration key to query
83 * @param mixed $default_value optional, The value to return if key is not set (default: null)
84 * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
86 * @return mixed Stored value or null if it does not exist
88 public static function get($family, $key, $default_value = null, $refresh = false)
90 // Database isn't ready or populated yet, fallback to file config
91 if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
92 return self::getApp()->getConfigValue($family, $key, $default_value);
95 if (empty(self::$adapter)) {
99 return self::$adapter->get($family, $key, $default_value, $refresh);
103 * @brief Sets a configuration value for system config
105 * Stores a config value ($value) in the category ($family) under the key ($key)
106 * for the user_id $uid.
108 * Note: Please do not store booleans - convert to 0/1 integer values!
110 * @param string $family The category of the configuration value
111 * @param string $key The configuration key to set
112 * @param mixed $value The value to store
114 * @return bool Operation success
116 public static function set($family, $key, $value)
118 // Database isn't ready or populated yet
119 if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
123 if (empty(self::$adapter)) {
127 return self::$adapter->set($family, $key, $value);
131 * @brief Deletes the given key from the system configuration.
133 * Removes the configured value from the stored cache in $a->config
134 * and removes it from the database.
136 * @param string $family The category of the configuration value
137 * @param string $key The configuration key to delete
141 public static function delete($family, $key)
143 // Database isn't ready or populated yet
144 if (!(self::getApp()->mode & App::MODE_DBCONFIGAVAILABLE)) {
148 if (empty(self::$adapter)) {
152 return self::$adapter->delete($family, $key);