Remove unnecessary classes

This commit is contained in:
Philipp 2022-12-28 00:20:20 +01:00
parent b871e1d264
commit d272e8c3c7
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
6 changed files with 2 additions and 492 deletions

View File

@ -1,121 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -1,75 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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);
}
}

View File

@ -1,149 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -1,145 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -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;

View File

@ -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