]> git.mxchange.org Git - friendica.git/blob - src/Core/Config.php
Config FollowUp
[friendica.git] / src / Core / Config.php
1 <?php
2 /**
3  * System Configuration Class
4  *
5  * @file include/Core/Config.php
6  *
7  * @brief Contains the class with methods for system configuration
8  */
9 namespace Friendica\Core;
10
11 use Friendica\Core\Config\ConfigCache;
12 use Friendica\Core\Config\IConfigAdapter;
13 use Friendica\Core\Config\IConfigCache;
14
15 /**
16  * @brief Arbitrary system configuration storage
17  *
18  * Note:
19  * If we ever would decide to return exactly the variable type as entered,
20  * we will have fun with the additional features. :-)
21  */
22 class Config
23 {
24         /**
25          * @var Config\Configuration
26          */
27         private static $config;
28
29         /**
30          * Initialize the config
31          *
32          * @param Config\Configuration $config
33          */
34         public static function init(Config\Configuration $config)
35         {
36                 self::$config = $config;
37         }
38
39         /**
40          * @brief Loads all configuration values of family into a cached storage.
41          *
42          * @param string $cat The category of the configuration value
43          *
44          * @return void
45          */
46         public static function load($cat = "config")
47         {
48                 self::$config->load($cat);
49         }
50
51         /**
52          * @brief Get a particular user's config variable given the category name
53          * ($family) and a key.
54          *
55          * @param string  $cat        The category of the configuration value
56          * @param string  $key           The configuration key to query
57          * @param mixed   $default_value optional, The value to return if key is not set (default: null)
58          * @param boolean $refresh       optional, If true the config is loaded from the db and not from the cache (default: false)
59          *
60          * @return mixed Stored value or null if it does not exist
61          */
62         public static function get($cat, $key, $default_value = null, $refresh = false)
63         {
64                 return self::$config->get($cat, $key, $default_value, $refresh);
65         }
66
67         /**
68          * @brief Sets a configuration value for system config
69          *
70          * Stores a config value ($value) in the category ($cat) under the key ($key)
71          *
72          * Note: Please do not store booleans - convert to 0/1 integer values!
73          *
74          * @param string $cat The category of the configuration value
75          * @param string $key    The configuration key to set
76          * @param mixed  $value  The value to store
77          *
78          * @return bool Operation success
79          */
80         public static function set($cat, $key, $value)
81         {
82                 return self::$config->set($cat, $key, $value);
83         }
84
85         /**
86          * @brief Deletes the given key from the system configuration.
87          *
88          * @param string $cat The category of the configuration value
89          * @param string $key    The configuration key to delete
90          *
91          * @return bool
92          */
93         public static function delete($cat, $key)
94         {
95                 return self::$config->delete($cat, $key);
96         }
97 }