2019-02-10 19:52:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Core\Config;
|
|
|
|
|
2019-07-03 00:42:47 +02:00
|
|
|
use Friendica\Model;
|
|
|
|
|
2019-02-10 19:52:21 +01:00
|
|
|
/**
|
|
|
|
* This class is responsible for all system-wide configuration values in Friendica
|
|
|
|
* There are two types of storage
|
2019-10-16 14:58:09 +02:00
|
|
|
* - The Config-Files (loaded into the FileCache @see Cache\ConfigCache)
|
|
|
|
* - The Config-DB-Table (per Config-DB-model @see Model\Config\Config)
|
2019-02-10 19:52:21 +01:00
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
abstract class Configuration
|
2019-02-10 19:52:21 +01:00
|
|
|
{
|
|
|
|
/**
|
2019-07-12 22:38:50 +02:00
|
|
|
* @var Cache\ConfigCache
|
2019-02-10 19:52:21 +01:00
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
protected $configCache;
|
2019-02-10 19:52:21 +01:00
|
|
|
|
|
|
|
/**
|
2019-07-03 00:42:47 +02:00
|
|
|
* @var Model\Config\Config
|
2019-02-10 19:52:21 +01:00
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
protected $configModel;
|
2019-02-10 19:52:21 +01:00
|
|
|
|
|
|
|
/**
|
2019-07-03 00:42:47 +02:00
|
|
|
* @param Cache\ConfigCache $configCache The configuration cache (based on the config-files)
|
|
|
|
* @param Model\Config\Config $configModel The configuration model
|
2019-02-10 19:52:21 +01:00
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
public function __construct(Cache\ConfigCache $configCache, Model\Config\Config $configModel)
|
2019-02-10 19:52:21 +01:00
|
|
|
{
|
|
|
|
$this->configCache = $configCache;
|
2019-07-03 00:42:47 +02:00
|
|
|
$this->configModel = $configModel;
|
2019-02-10 19:52:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-14 22:26:36 +02:00
|
|
|
* Returns the Config Cache
|
|
|
|
*
|
|
|
|
* @return Cache\ConfigCache
|
2019-02-10 19:52:21 +01:00
|
|
|
*/
|
|
|
|
public function getCache()
|
|
|
|
{
|
|
|
|
return $this->configCache;
|
|
|
|
}
|
|
|
|
|
2019-07-14 22:31:53 +02:00
|
|
|
/**
|
|
|
|
* @brief Loads all configuration values of family into a cached storage.
|
|
|
|
*
|
2019-06-23 19:56:21 +02:00
|
|
|
* All configuration values of the system are stored in the cache ( @see ConfigCache )
|
2019-07-14 22:31:53 +02:00
|
|
|
*
|
|
|
|
* @param string $cat The category of the configuration value
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
abstract public function load(string $cat = 'config');
|
2019-07-14 22:31:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
2019-10-16 14:58:09 +02:00
|
|
|
* (@see IConfigAdapter) or from the $this->configCache (@see ConfigCache).
|
2019-07-14 22:31:53 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
abstract public function get(string $cat, string $key, $default_value = null, bool $refresh = false);
|
2019-07-14 22:31:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
abstract public function set(string $cat, string $key, $value);
|
2019-07-14 22:31:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deletes the given key from the system configuration.
|
|
|
|
*
|
|
|
|
* Removes the configured value from the stored cache in $this->configCache
|
2019-10-16 14:58:09 +02:00
|
|
|
* (@see ConfigCache) and removes it from the database (@see IConfigAdapter).
|
2019-07-14 22:31:53 +02:00
|
|
|
*
|
|
|
|
* @param string $cat The category of the configuration value
|
|
|
|
* @param string $key The configuration key to delete
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
abstract public function delete(string $cat, string $key);
|
2019-02-10 19:52:21 +01:00
|
|
|
}
|