]> git.mxchange.org Git - friendica.git/blob - src/Core/Config/PConfiguration.php
Merge pull request #7754 from annando/aria
[friendica.git] / src / Core / Config / PConfiguration.php
1 <?php
2
3 namespace Friendica\Core\Config;
4
5 use Friendica\Model;
6
7 /**
8  * This class is responsible for the user-specific configuration values in Friendica
9  * The values are set through the Config-DB-Table (per Config-DB-model @see Model\Config\PConfig)
10  *
11  * The configuration cache (@see Cache\PConfigCache) is used for temporary caching of database calls. This will
12  * increase the performance.
13  */
14 abstract class PConfiguration
15 {
16         /**
17          * @var Cache\PConfigCache
18          */
19         protected $configCache;
20
21         /**
22          * @var Model\Config\PConfig
23          */
24         protected $configModel;
25
26         /**
27          * @param Cache\PConfigCache   $configCache The configuration cache
28          * @param Model\Config\PConfig $configModel The configuration model
29          */
30         public function __construct(Cache\PConfigCache $configCache, Model\Config\PConfig $configModel)
31         {
32                 $this->configCache = $configCache;
33                 $this->configModel = $configModel;
34         }
35
36         /**
37          * Returns the Config Cache
38          *
39          * @return Cache\PConfigCache
40          */
41         public function getCache()
42         {
43                 return $this->configCache;
44         }
45
46         /**
47          * Loads all configuration values of a user's config family into a cached storage.
48          *
49          * All configuration values of the given user are stored with the $uid in the cache
50          *
51          * @param int $uid The user_id
52          * @param string $cat The category of the configuration value
53          *
54          * @return void
55          * @see PConfigCache
56          *
57          */
58         abstract public function load(int $uid, string $cat = 'config');
59
60         /**
61          * Get a particular user's config variable given the category name
62          * ($cat) and a key.
63          *
64          * Get a particular user's config value from the given category ($cat)
65          * and the $key with the $uid from a cached storage either from the $this->configAdapter
66          * (@see IConfigAdapter) or from the $this->configCache (@see PConfigCache).
67          *
68          * @param int     $uid           The user_id
69          * @param string  $cat           The category of the configuration value
70          * @param string  $key           The configuration key to query
71          * @param mixed   $default_value optional, The value to return if key is not set (default: null)
72          * @param boolean $refresh       optional, If true the config is loaded from the db and not from the cache (default: false)
73          *
74          * @return mixed Stored value or null if it does not exist
75          */
76         abstract public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false);
77
78         /**
79          * Sets a configuration value for a user
80          *
81          * Stores a config value ($value) in the category ($family) under the key ($key)
82          * for the user_id $uid.
83          *
84          * @note  Please do not store booleans - convert to 0/1 integer values!
85          *
86          * @param int    $uid   The user_id
87          * @param string $cat   The category of the configuration value
88          * @param string $key   The configuration key to set
89          * @param mixed  $value The value to store
90          *
91          * @return bool Operation success
92          */
93         abstract public function set(int $uid, string $cat, string $key, $value);
94
95         /**
96          * Deletes the given key from the users's configuration.
97          *
98          * Removes the configured value from the stored cache in $this->configCache
99          * (@see ConfigCache) and removes it from the database (@see IConfigAdapter)
100          *  with the given $uid.
101          *
102          * @param int $uid The user_id
103          * @param string $cat The category of the configuration value
104          * @param string $key The configuration key to delete
105          *
106          * @return bool
107          */
108         abstract public function delete(int $uid, string $cat, string $key);
109 }