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