]> git.mxchange.org Git - friendica.git/blob - src/Core/PConfig.php
Preload Adapter Fix
[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          * @note  Please do not store booleans - convert to 0/1 integer values!
69          *
70          * @param string $uid    The user_id
71          * @param string $cat    The category of the configuration value
72          * @param string $key    The configuration key to set
73          * @param mixed  $value  The value to store
74          *
75          * @return bool Operation success
76          */
77         public static function set($uid, $cat, $key, $value)
78         {
79                 return self::$config->set($uid, $cat, $key, $value);
80         }
81
82         /**
83          * @brief Deletes the given key from the users's configuration.
84          *
85          * @param string $uid The user_id
86          * @param string $cat The category of the configuration value
87          * @param string $key The configuration key to delete
88          *
89          * @return bool
90          */
91         public static function delete($uid, $cat, $key)
92         {
93                 return self::$config->delete($uid, $cat, $key);
94         }
95 }