]> git.mxchange.org Git - friendica.git/blob - src/Core/Config/PConfiguration.php
Refactor PConfiguration
[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-adapter @see Adapter\IPConfigAdapter )
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
50          * the cache ( @param int $uid The user_id
51          *
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          * (@param int $uid The user_id
67          *
68          * @param string  $cat           The category of the configuration value
69          * @param string  $key           The configuration key to query
70          * @param mixed   $default_value optional, The value to return if key is not set (default: null)
71          * @param boolean $refresh       optional, If true the config is loaded from the db and not from the cache (default: false)
72          *
73          * @return mixed Stored value or null if it does not exist
74          * @see IConfigAdapter ) or from the $this->configCache (@see PConfigCache ).
75          *
76          */
77         abstract public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false);
78
79         /**
80          * Sets a configuration value for a user
81          *
82          * Stores a config value ($value) in the category ($family) under the key ($key)
83          * for the user_id $uid.
84          *
85          * @note  Please do not store booleans - convert to 0/1 integer values!
86          *
87          * @param int    $uid   The user_id
88          * @param string $cat   The category of the configuration value
89          * @param string $key   The configuration key to set
90          * @param mixed  $value The value to store
91          *
92          * @return bool Operation success
93          */
94         abstract public function set(int $uid, string $cat, string $key, $value);
95
96         /**
97          * Deletes the given key from the users's configuration.
98          *
99          * Removes the configured value from the stored cache in $this->configCache
100          * (@param int $uid The user_id
101          *
102          * @param string $cat The category of the configuration value
103          * @param string $key The configuration key to delete
104          *
105          * @return bool
106          * @see ConfigCache ) and removes it from the database (@see IConfigAdapter )
107          *      with the given $uid.
108          *
109          */
110         abstract public function delete(int $uid, string $cat, string $key);
111 }