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