From d272e8c3c78b88c45a0eb860f8491ccd6f3d7a62 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 28 Dec 2022 00:20:20 +0100 Subject: [PATCH] Remove unnecessary classes --- src/Core/Config/Repository/Config.php | 121 -------------- src/Core/Config/Type/AbstractConfig.php | 75 --------- src/Core/Config/Type/JitConfig.php | 149 ------------------ src/Core/Config/Type/PreloadConfig.php | 145 ----------------- src/Core/PConfig/Repository/PConfig.php | 2 +- .../Util/ValueConversion.php | 2 +- 6 files changed, 2 insertions(+), 492 deletions(-) delete mode 100644 src/Core/Config/Repository/Config.php delete mode 100644 src/Core/Config/Type/AbstractConfig.php delete mode 100644 src/Core/Config/Type/JitConfig.php delete mode 100644 src/Core/Config/Type/PreloadConfig.php rename src/Core/{Config => PConfig}/Util/ValueConversion.php (98%) diff --git a/src/Core/Config/Repository/Config.php b/src/Core/Config/Repository/Config.php deleted file mode 100644 index eabff9e68f..0000000000 --- a/src/Core/Config/Repository/Config.php +++ /dev/null @@ -1,121 +0,0 @@ -. - * - */ - -namespace Friendica\Core\Config\Repository; - -use Friendica\App\Mode; -use Friendica\Core\Config\Exception\ConfigPersistenceException; -use Friendica\Core\Config\Util\ValueConversion; -use Friendica\Database\Database; - -/** - * The Config Repository, which is using the general DB-model backend for configs - */ -class Config -{ - /** @var Database */ - protected $db; - /** @var Mode */ - protected $mode; - - public function __construct(Database $db, Mode $mode) - { - $this->db = $db; - $this->mode = $mode; - } - - protected static $table_name = 'config'; - - /** - * Checks if the model is currently connected - * - * @return bool - */ - public function isConnected(): bool - { - return true; - } - - /** - * Loads all configuration values and returns the loaded category as an array. - * - * @param string|null $cat The category of the configuration values to load - * - * @return array The config array - * - * @throws ConfigPersistenceException In case the persistence layer throws errors - */ - public function load(?string $cat = null): array - { - return []; - } - - /** - * Get a particular, system-wide config variable out of the DB with the - * given category name ($cat) and a key ($key). - * - * Note: Boolean variables are defined as 0/1 in the database - * - * @param string $cat The category of the configuration value - * @param string $key The configuration key to query - * - * @return array|string|null Stored value or null if it does not exist - * - * @throws ConfigPersistenceException In case the persistence layer throws errors - */ - public function get(string $cat, string $key) - { - return null; - } - - /** - * 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 - * - * @throws ConfigPersistenceException In case the persistence layer throws errors - */ - public function set(string $cat, string $key, $value): bool - { - return true; - } - - /** - * Removes the configured value from the database. - * - * @param string $cat The category of the configuration value - * @param string $key The configuration key to delete - * - * @return bool Operation success - * - * @throws ConfigPersistenceException In case the persistence layer throws errors - */ - public function delete(string $cat, string $key): bool - { - return true; - } -} diff --git a/src/Core/Config/Type/AbstractConfig.php b/src/Core/Config/Type/AbstractConfig.php deleted file mode 100644 index fa98dd7097..0000000000 --- a/src/Core/Config/Type/AbstractConfig.php +++ /dev/null @@ -1,75 +0,0 @@ -. - * - */ - -namespace Friendica\Core\Config\Type; - -use Friendica\Core\Config\Repository\Config; -use Friendica\Core\Config\Util\ConfigFileManager; -use Friendica\Core\Config\ValueObject\Cache; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\DI; - -/** - * This class is responsible for all system-wide configuration values in Friendica - * There are two types of storage - * - The Config-Files (loaded into the FileCache @see Cache) - * - The Config-Repository (per Config-Repository @see Config ) - */ -abstract class AbstractConfig implements IManageConfigValues -{ - /** - * @var Cache - */ - protected $configCache; - - /** - * @var Config - */ - protected $configRepo; - - /** @var ConfigFileManager */ - protected $configFileManager; - - /** - * @param ConfigFileManager $configFileManager The configuration file manager to save back configs - * @param Cache $configCache The configuration cache (based on the config-files) - * @param Config $configRepo The configuration repository - */ - public function __construct(ConfigFileManager $configFileManager, Cache $configCache, Config $configRepo) - { - $this->configFileManager = $configFileManager; - $this->configCache = $configCache; - $this->configRepo = $configRepo; - } - - /** - * {@inheritDoc} - */ - public function getCache(): Cache - { - return $this->configCache; - } - - public function save() - { - $this->configFileManager->saveData($this->configCache); - } -} diff --git a/src/Core/Config/Type/JitConfig.php b/src/Core/Config/Type/JitConfig.php deleted file mode 100644 index 1ae9abd2ee..0000000000 --- a/src/Core/Config/Type/JitConfig.php +++ /dev/null @@ -1,149 +0,0 @@ -. - * - */ - -namespace Friendica\Core\Config\Type; - -use Friendica\Core\Config\Util\ConfigFileManager; -use Friendica\Core\Config\ValueObject\Cache; -use Friendica\Core\Config\Repository\Config; - -/** - * This class implements the Just-In-Time configuration, which will cache - * config values in a cache, once they are retrieved. - * - * Default Configuration type. - * Provides the best performance for pages loading few configuration variables. - */ -class JitConfig extends AbstractConfig -{ - /** - * @var array Array of already loaded db values (even if there was no value) - */ - private $db_loaded; - - /** - * @param ConfigFileManager $configFileManager The configuration file manager to save back configs - * @param Cache $configCache The configuration cache (based on the config-files) - * @param Config $configRepo The configuration model - */ - public function __construct(ConfigFileManager $configFileManager, Cache $configCache, Config $configRepo) - { - parent::__construct($configFileManager, $configCache, $configRepo); - $this->db_loaded = []; - - $this->load(); - } - - /** - * {@inheritDoc} - */ - public function load(string $cat = 'config') - { - // If not connected, do nothing - if (!$this->configRepo->isConnected()) { - return; - } - - $config = $this->configRepo->load($cat); - - if (!empty($config[$cat])) { - foreach ($config[$cat] as $key => $value) { - $this->db_loaded[$cat][$key] = true; - } - } - - // load the whole category out of the DB into the cache - $this->configCache->load($config, Cache::SOURCE_DATA); - } - - /** - * {@inheritDoc} - */ - public function get(string $cat, string $key, $default_value = null, bool $refresh = false) - { - // if the value isn't loaded or refresh is needed, load it to the cache - if ($this->configRepo->isConnected() && - (empty($this->db_loaded[$cat][$key]) || - $refresh)) { - $dbValue = $this->configRepo->get($cat, $key); - - if (isset($dbValue)) { - $this->configCache->set($cat, $key, $dbValue, Cache::SOURCE_DATA); - unset($dbValue); - } - - $this->db_loaded[$cat][$key] = true; - } - - // use the config cache for return - $result = $this->configCache->get($cat, $key); - - return (isset($result)) ? $result : $default_value; - } - - /** - * {@inheritDoc} - */ - public function set(string $cat, string $key, $value, bool $autosave = true): bool - { - // set the cache first - $cached = $this->configCache->set($cat, $key, $value, Cache::SOURCE_DATA); - - // If there is no connected adapter, we're finished - if (!$this->configRepo->isConnected()) { - return $cached; - } - - $stored = $this->configRepo->set($cat, $key, $value); - - $this->db_loaded[$cat][$key] = $stored; - - if ($autosave) { - $this->save(); - } - - return $cached && $stored; - } - - /** - * {@inheritDoc} - */ - public function delete(string $cat, string $key, bool $autosave = true): bool - { - $cacheRemoved = $this->configCache->delete($cat, $key); - - if (isset($this->db_loaded[$cat][$key])) { - unset($this->db_loaded[$cat][$key]); - } - - if (!$this->configRepo->isConnected()) { - return $cacheRemoved; - } - - $storeRemoved = $this->configRepo->delete($cat, $key); - - if ($autosave) { - $this->save(); - } - - return $cacheRemoved || $storeRemoved; - } -} diff --git a/src/Core/Config/Type/PreloadConfig.php b/src/Core/Config/Type/PreloadConfig.php deleted file mode 100644 index 6eed20af89..0000000000 --- a/src/Core/Config/Type/PreloadConfig.php +++ /dev/null @@ -1,145 +0,0 @@ -. - * - */ - -namespace Friendica\Core\Config\Type; - -use Friendica\Core\Config\Util\ConfigFileManager; -use Friendica\Core\Config\ValueObject\Cache; -use Friendica\Core\Config\Repository\Config; - -/** - * This class implements the preload configuration, which will cache - * all config values per call in a cache. - * - * Minimizes the number of database queries to retrieve configuration values at the cost of memory. - */ -class PreloadConfig extends AbstractConfig -{ - /** @var bool */ - private $config_loaded; - - /** - * @param ConfigFileManager $configFileManager The configuration file manager to save back configs - * @param Cache $configCache The configuration cache (based on the config-files) - * @param Config $configRepo The configuration model - */ - public function __construct(ConfigFileManager $configFileManager, Cache $configCache, Config $configRepo) - { - parent::__construct($configFileManager, $configCache, $configRepo); - $this->config_loaded = false; - - $this->load(); - } - - /** - * {@inheritDoc} - * - * This loads all config values everytime load is called - */ - public function load(string $cat = 'config') - { - // Don't load the whole configuration twice - if ($this->config_loaded) { - return; - } - - // If not connected, do nothing - if (!$this->configRepo->isConnected()) { - return; - } - - $config = $this->configRepo->load(); - $this->config_loaded = true; - - // load the whole category out of the DB into the cache - $this->configCache->load($config, Cache::SOURCE_DATA); - } - - /** - * {@inheritDoc} - */ - public function get(string $cat, string $key, $default_value = null, bool $refresh = false) - { - if ($refresh) { - if ($this->configRepo->isConnected()) { - $config = $this->configRepo->get($cat, $key); - if (isset($config)) { - $this->configCache->set($cat, $key, $config, Cache::SOURCE_DATA); - } - } - } - - // use the config cache for return - $result = $this->configCache->get($cat, $key); - - return (isset($result)) ? $result : $default_value; - } - - /** - * {@inheritDoc} - */ - public function set(string $cat, string $key, $value, bool $autosave = true): bool - { - if (!$this->config_loaded) { - $this->load(); - } - - // set the cache first - $cached = $this->configCache->set($cat, $key, $value, Cache::SOURCE_DATA); - - // If there is no connected adapter, we're finished - if (!$this->configRepo->isConnected()) { - return $cached; - } - - $stored = $this->configRepo->set($cat, $key, $value); - - if ($autosave) { - $this->save(); - } - - return $cached && $stored; - } - - /** - * {@inheritDoc} - */ - public function delete(string $cat, string $key, bool $autosave = true): bool - { - if ($this->config_loaded) { - $this->load(); - } - - $cacheRemoved = $this->configCache->delete($cat, $key); - - if (!$this->configRepo->isConnected()) { - return $cacheRemoved; - } - - $storeRemoved = $this->configRepo->delete($cat, $key); - - if ($autosave) { - $this->save(); - } - - return $cacheRemoved || $storeRemoved; - } -} diff --git a/src/Core/PConfig/Repository/PConfig.php b/src/Core/PConfig/Repository/PConfig.php index 5c9d2d51d1..506aaeb5a7 100644 --- a/src/Core/PConfig/Repository/PConfig.php +++ b/src/Core/PConfig/Repository/PConfig.php @@ -22,7 +22,7 @@ namespace Friendica\Core\PConfig\Repository; use Friendica\App\Mode; -use Friendica\Core\Config\Util\ValueConversion; +use Friendica\Core\PConfig\Util\ValueConversion; use Friendica\Core\PConfig\Exception\PConfigPersistenceException; use Friendica\Database\Database; diff --git a/src/Core/Config/Util/ValueConversion.php b/src/Core/PConfig/Util/ValueConversion.php similarity index 98% rename from src/Core/Config/Util/ValueConversion.php rename to src/Core/PConfig/Util/ValueConversion.php index a3d9d0146a..64a4bfc51f 100644 --- a/src/Core/Config/Util/ValueConversion.php +++ b/src/Core/PConfig/Util/ValueConversion.php @@ -19,7 +19,7 @@ * */ -namespace Friendica\Core\Config\Util; +namespace Friendica\Core\PConfig\Util; /** * Util class to help to convert from/to (p)config values