* @param array $config A initial config array
* @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
*/
- public function __construct(array $config = [], $hidePasswordOutput = true)
+ public function __construct(array $config = [], bool $hidePasswordOutput = true)
{
$this->hidePasswordOutput = $hidePasswordOutput;
$this->load($config);
* @param array $config
* @param bool $overwrite Force value overwrite if the config key already exists
*/
- public function load(array $config, $overwrite = false)
+ public function load(array $config, bool $overwrite = false)
{
$categories = array_keys($config);
*
* @return null|mixed Returns the value of the Config entry or null if not set
*/
- public function get($cat, $key = null)
+ public function get(string $cat, string $key = null)
{
if (isset($this->config[$cat][$key])) {
return $this->config[$cat][$key];
/**
* Sets a default value in the config cache. Ignores already existing keys.
*
- * @param string $cat Config category
- * @param string $k Config key
- * @param mixed $v Default value to set
+ * @param string $cat Config category
+ * @param string $key Config key
+ * @param mixed $value Default value to set
*/
- private function setDefault($cat, $k, $v)
+ private function setDefault(string $cat, string $key, $value)
{
- if (!isset($this->config[$cat][$k])) {
- $this->set($cat, $k, $v);
+ if (!isset($this->config[$cat][$key])) {
+ $this->set($cat, $key, $value);
}
}
*
* @return bool True, if the value is set
*/
- public function set($cat, $key, $value)
+ public function set(string $cat, string $key, $value)
{
if (!isset($this->config[$cat])) {
$this->config[$cat] = [];
if ($this->hidePasswordOutput &&
$key == 'password' &&
is_string($value)) {
- $this->config[$cat][$key] = new HiddenString((string) $value);
+ $this->config[$cat][$key] = new HiddenString((string)$value);
} else {
$this->config[$cat][$key] = $value;
}
*
* @return bool true, if deleted
*/
- public function delete($cat, $key)
+ public function delete(string $cat, string $key)
{
if (isset($this->config[$cat][$key])) {
unset($this->config[$cat][$key]);
private $hidePasswordOutput;
/**
- * @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
+ * @param bool $hidePasswordOutput True, if cache variables should take extra care of password values
*/
- public function __construct($hidePasswordOutput = true)
+ public function __construct(bool $hidePasswordOutput = true)
{
$this->hidePasswordOutput = $hidePasswordOutput;
}
* @param int $uid
* @param array $config
*/
- public function load($uid, array $config)
+ public function load(int $uid, array $config)
{
$categories = array_keys($config);
/**
* Retrieves a value from the user config cache
*
- * @param int $uid User Id
- * @param string $cat Config category
- * @param string $key Config key
+ * @param int $uid User Id
+ * @param string $cat Config category
+ * @param string $key Config key
*
* @return null|string The value of the config entry or null if not set
*/
- public function get($uid, $cat, $key = null)
+ public function get(int $uid, string $cat, $key = null)
{
if (isset($this->config[$uid][$cat][$key])) {
return $this->config[$uid][$cat][$key];
*
* @return bool Set successful
*/
- public function set($uid, $cat, $key, $value)
+ public function set(int $uid, string $cat, string $key, $value)
{
if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
$this->config[$uid] = [];
if ($this->hidePasswordOutput &&
$key == 'password' &&
!empty($value) && is_string($value)) {
- $this->config[$uid][$cat][$key] = new HiddenString((string) $value);
+ $this->config[$uid][$cat][$key] = new HiddenString((string)$value);
} else {
$this->config[$uid][$cat][$key] = $value;
}
*
* @return bool true, if deleted
*/
- public function delete($uid, $cat, $key)
+ public function delete(int $uid, string $cat, string $key)
{
if (isset($this->config[$uid][$cat][$key])) {
unset($this->config[$uid][$cat][$key]);
return $this->configCache;
}
+ /**
+ * @brief Loads all configuration values of family into a cached storage.
+ *
+ * All configuration values of the system are stored in the cache ( @see IConfigCache )
+ *
+ * @param string $cat The category of the configuration value
+ *
+ * @return void
+ */
abstract public function load(string $cat = 'config');
+
+ /**
+ * @brief Get a particular user's config variable given the category name
+ * ($cat) and a $key.
+ *
+ * Get a particular config value from the given category ($cat)
+ * and the $key from a cached storage either from the $this->configAdapter
+ * (@see IConfigAdapter ) or from the $this->configCache (@see IConfigCache ).
+ *
+ * @param string $cat The category of the configuration value
+ * @param string $key The configuration key to query
+ * @param mixed $default_value optional, The value to return if key is not set (default: null)
+ * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false)
+ *
+ * @return mixed Stored value or null if it does not exist
+ */
abstract public function get(string $cat, string $key, $default_value = null, bool $refresh = false);
+
+ /**
+ * @brief Sets a configuration value for system config
+ *
+ * Stores a config value ($value) in the category ($cat) under the key ($key)
+ *
+ * Note: Please do not store booleans - convert to 0/1 integer values!
+ *
+ * @param string $cat The category of the configuration value
+ * @param string $key The configuration key to set
+ * @param mixed $value The value to store
+ *
+ * @return bool Operation success
+ */
abstract public function set(string $cat, string $key, $value);
+
+ /**
+ * @brief Deletes the given key from the system configuration.
+ *
+ * Removes the configured value from the stored cache in $this->configCache
+ * (@see ConfigCache ) and removes it from the database (@see IConfigAdapter ).
+ *
+ * @param string $cat The category of the configuration value
+ * @param string $key The configuration key to delete
+ *
+ * @return bool
+ */
abstract public function delete(string $cat, string $key);
}