]> git.mxchange.org Git - friendica.git/blob - src/Core/PConfig.php
Use direct logic
[friendica.git] / src / Core / PConfig.php
1 <?php
2 /**
3  * User Configuration Class
4  *
5  * @file include/Core/PConfig.php
6  *
7  * @brief Contains the class with methods for user configuration
8  */
9 namespace Friendica\Core;
10
11 /**
12  * @brief Management of user configuration storage
13  * Note:
14  * Please do not store booleans - convert to 0/1 integer values
15  * The PConfig::get() functions return boolean false for keys that are unset,
16  * and this could lead to subtle bugs.
17  */
18 class PConfig
19 {
20         /**
21          * @var Config\PConfiguration
22          */
23         private static $config;
24
25         /**
26          * Initialize the config with only the cache
27          *
28          * @param Config\PConfiguration $config The configuration cache
29          */
30         public static function init(Config\PConfiguration $config)
31         {
32                 self::$config = $config;
33         }
34
35         /**
36          * @brief Loads all configuration values of a user's config family into a cached storage.
37          *
38          * @param string $uid The user_id
39          * @param string $cat The category of the configuration value
40          *
41          * @return void
42          */
43         public static function load($uid, $cat)
44         {
45                 self::$config->load($uid, $cat);
46         }
47
48         /**
49          * @brief Get a particular user's config variable given the category name
50          * ($cat) and a key.
51          *
52          * @param string  $uid           The user_id
53          * @param string  $cat           The category of the configuration value
54          * @param string  $key           The configuration key to query
55          * @param mixed   $default_value optional, The value to return if key is not set (default: null)
56          * @param boolean $refresh       optional, If true the config is loaded from the db and not from the cache (default: false)
57          *
58          * @return mixed Stored value or null if it does not exist
59          */
60         public static function get($uid, $cat, $key, $default_value = null, $refresh = false)
61         {
62                 return self::$config->get($uid, $cat, $key, $default_value, $refresh);
63         }
64
65         /**
66          * @brief Sets a configuration value for a user
67          *
68          * @param string $uid    The user_id
69          * @param string $cat    The category of the configuration value
70          * @param string $key    The configuration key to set
71          * @param mixed  $value  The value to store
72          *
73          * @return bool Operation success
74          */
75         public static function set($uid, $cat, $key, $value)
76         {
77                 return self::$config->set($uid, $cat, $key, $value);
78         }
79
80         /**
81          * @brief Deletes the given key from the users's configuration.
82          *
83          * @param string $uid The user_id
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($uid, $cat, $key)
90         {
91                 return self::$config->delete($uid, $cat, $key);
92         }
93 }