<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
namespace Friendica\Core\Config\Type;
-use Friendica\Core\Config\Cache\Cache;
-use Friendica\Core\Config\Model\Config;
+use Friendica\Core\Config\ValueObject\Cache;
+use Friendica\Core\Config\Repository\Config;
/**
* This class implements the Just-In-Time configuration, which will cache
* Default Configuration type.
* Provides the best performance for pages loading few configuration variables.
*/
-class JitConfig extends BaseConfig
+class JitConfig extends AbstractConfig
{
/**
* @var array Array of already loaded db values (even if there was no value)
private $db_loaded;
/**
- * @param Cache $configCache The configuration cache (based on the config-files)
- * @param Config $configModel The configuration model
+ * @param Cache $configCache The configuration cache (based on the config-files)
+ * @param Config $configRepo The configuration model
*/
- public function __construct(Cache $configCache, Config $configModel)
+ public function __construct(Cache $configCache, Config $configRepo)
{
- parent::__construct($configCache, $configModel);
+ parent::__construct($configCache, $configRepo);
$this->db_loaded = [];
$this->load();
/**
* {@inheritDoc}
- *
*/
public function load(string $cat = 'config')
{
// If not connected, do nothing
- if (!$this->configModel->isConnected()) {
+ if (!$this->configRepo->isConnected()) {
return;
}
- $config = $this->configModel->load($cat);
+ $config = $this->configRepo->load($cat);
if (!empty($config[$cat])) {
foreach ($config[$cat] as $key => $value) {
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->configModel->isConnected() &&
- (empty($this->db_loaded[$cat][$key]) ||
- $refresh)) {
-
- $dbvalue = $this->configModel->get($cat, $key);
-
- if (isset($dbvalue)) {
- $this->configCache->set($cat, $key, $dbvalue, Cache::SOURCE_DB);
- unset($dbvalue);
+ 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_DB);
+ unset($dbValue);
}
$this->db_loaded[$cat][$key] = true;
/**
* {@inheritDoc}
*/
- public function set(string $cat, string $key, $value)
+ public function set(string $cat, string $key, $value): bool
{
// set the cache first
$cached = $this->configCache->set($cat, $key, $value, Cache::SOURCE_DB);
// If there is no connected adapter, we're finished
- if (!$this->configModel->isConnected()) {
+ if (!$this->configRepo->isConnected()) {
return $cached;
}
- $stored = $this->configModel->set($cat, $key, $value);
+ $stored = $this->configRepo->set($cat, $key, $value);
$this->db_loaded[$cat][$key] = $stored;
/**
* {@inheritDoc}
*/
- public function delete(string $cat, string $key)
+ public function delete(string $cat, string $key): bool
{
$cacheRemoved = $this->configCache->delete($cat, $key);
unset($this->db_loaded[$cat][$key]);
}
- if (!$this->configModel->isConnected()) {
+ if (!$this->configRepo->isConnected()) {
return $cacheRemoved;
}
- $storeRemoved = $this->configModel->delete($cat, $key);
+ $storeRemoved = $this->configRepo->delete($cat, $key);
return $cacheRemoved || $storeRemoved;
}