3 namespace Friendica\Model\Config;
6 class Config extends DbaConfig
9 * Loads all configuration values and returns the loaded category as an array.
11 * @param string $cat The category of the configuration values to load
15 public function load(string $cat = null)
20 $configs = $this->dba->select('config', ['cat', 'v', 'k']);
22 $configs = $this->dba->select('config', ['cat', 'v', 'k'], ['cat' => $cat]);
25 while ($config = $this->dba->fetch($configs)) {
28 $value = $this->toConfigValue($config['v']);
30 // just save it in case it is set
32 $return[$config['cat']][$key] = $value;
35 $this->dba->close($configs);
41 * Get a particular system-wide config variable given the category name
42 * ($cat) and a key ($key).
44 * Note: Boolean variables are defined as 0/1 in the database
46 * @param string $cat The category of the configuration value
47 * @param string $key The configuration key to query
49 * @return null|mixed Stored value or null if it does not exist
51 public function get(string $cat, string $key)
53 if (!$this->isConnected()) {
57 $config = $this->dba->selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
58 if ($this->dba->isResult($config)) {
59 $value = $this->toConfigValue($config['v']);
61 // just return it in case it is set
71 * Stores a config value ($value) in the category ($cat) under the key ($key).
73 * Note: Please do not store booleans - convert to 0/1 integer values!
75 * @param string $cat The category of the configuration value
76 * @param string $key The configuration key to set
77 * @param mixed $value The value to store
79 * @return bool Operation success
81 public function set(string $cat, string $key, $value)
83 if (!$this->isConnected()) {
87 // We store our setting values in a string variable.
88 // So we have to do the conversion here so that the compare below works.
89 // The exception are array values.
90 $compare_value = (!is_array($value) ? (string)$value : $value);
91 $stored_value = $this->get($cat, $key);
93 if (isset($stored_value) && ($stored_value === $compare_value)) {
97 $dbvalue = $this->toDbValue($value);
99 $result = $this->dba->update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
105 * Removes the configured value from the stored cache
106 * and removes it from the database.
108 * @param string $cat The category of the configuration value
109 * @param string $key The configuration key to delete
111 * @return bool Operation success
113 public function delete(string $cat, string $key)
115 if (!$this->isConnected()) {
119 return $this->dba->delete('config', ['cat' => $cat, 'k' => $key]);