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