3 * System Configuration Class
5 * @file include/Core/Config.php
7 * @brief Contains the class with methods for system configuration
9 namespace Friendica\Core;
11 use Friendica\Core\Config\ConfigCache;
12 use Friendica\Core\Config\IConfigAdapter;
13 use Friendica\Core\Config\IConfigCache;
16 * @brief Arbitrary system configuration storage
19 * If we ever would decide to return exactly the variable type as entered,
20 * we will have fun with the additional features. :-)
25 * @var Config\IConfigAdapter
27 private static $adapter;
30 * @var Config\IConfigCache
32 private static $cache;
35 * Initialize the config with only the cache
37 * @param Config\IConfigCache $cache The configuration cache
39 public static function init(Config\IConfigCache $cache)
41 self::$cache = $cache;
45 * Add the adapter for DB-backend
47 * @param Config\IConfigAdapter $adapter
49 public static function setAdapter(Config\IConfigAdapter $adapter)
51 self::$adapter = $adapter;
55 * @brief Loads all configuration values of family into a cached storage.
57 * All configuration values of the system are stored in the cache ( @see IConfigCache )
59 * @param string $family The category of the configuration value
63 public static function load($family = "config")
65 if (!isset(self::$adapter)) {
69 self::$adapter->load($family);
73 * @brief Get a particular user's config variable given the category name
74 * ($family) and a key.
76 * Get a particular config value from the given category ($family)
77 * and the $key from a cached storage either from the self::$adapter
78 * (@see IConfigAdapter ) or from the static::$cache (@see IConfigCache ).
80 * @param string $family The category of the configuration value
81 * @param string $key The configuration key to query
82 * @param mixed $default_value optional, The value to return if key is not set (default: null)
83 * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
85 * @return mixed Stored value or null if it does not exist
87 public static function get($family, $key, $default_value = null, $refresh = false)
89 if (!isset(self::$adapter)) {
90 return self::$cache->get($family, $key, $default_value);
93 return self::$adapter->get($family, $key, $default_value, $refresh);
97 * @brief Sets a configuration value for system config
99 * Stores a config value ($value) in the category ($family) under the key ($key)
101 * Note: Please do not store booleans - convert to 0/1 integer values!
103 * @param string $family The category of the configuration value
104 * @param string $key The configuration key to set
105 * @param mixed $value The value to store
107 * @return bool Operation success
109 public static function set($family, $key, $value)
111 if (!isset(self::$adapter)) {
112 self::$cache->set($family, $key, $value);
116 return self::$adapter->set($family, $key, $value);
120 * @brief Deletes the given key from the system configuration.
122 * Removes the configured value from the stored cache in self::$config
123 * (@see ConfigCache ) and removes it from the database (@see IConfigAdapter ).
125 * @param string $family The category of the configuration value
126 * @param string $key The configuration key to delete
130 public static function delete($family, $key)
132 if (!isset(self::$adapter)) {
133 self::$cache->delete($family, $key);
136 return self::$adapter->delete($family, $key);