<?php
namespace Friendica\Core\Config;
-use Friendica\Core\PConfig;
use Friendica\Database\DBA;
/**
{
private $in_db;
+ /**
+ * The config cache of this adapter
+ * @var IPConfigCache
+ */
+ private $configCache;
+
+ /**
+ * @param IPConfigCache $configCache The config cache of this adapter
+ */
+ public function __construct(IPConfigCache $configCache)
+ {
+ $this->configCache = $configCache;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function load($uid, $cat)
{
$pconfigs = DBA::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]);
while ($pconfig = DBA::fetch($pconfigs)) {
$k = $pconfig['k'];
- PConfig::setPConfigValue($uid, $cat, $k, $pconfig['v']);
+ $this->configCache->setP($uid, $cat, $k, $pconfig['v']);
$this->in_db[$uid][$cat][$k] = true;
}
} else if ($cat != 'config') {
// Negative caching
- PConfig::setPConfigValue($uid, $cat, "!<unset>!");
+ $this->configCache->setP($uid, $cat, null, "!<unset>!");
}
DBA::close($pconfigs);
}
+ /**
+ * {@inheritdoc}
+ */
public function get($uid, $cat, $k, $default_value = null, $refresh = false)
{
if (!$refresh) {
// Looking if the whole family isn't set
- if (PConfig::getPConfigValue($uid, $cat) !== null) {
- if (PConfig::getPConfigValue($uid, $cat) === '!<unset>!') {
+ if ($this->configCache->getP($uid, $cat) !== null) {
+ if ($this->configCache->getP($uid, $cat) === '!<unset>!') {
return $default_value;
}
}
- if (PConfig::getPConfigValue($uid, $cat, $k) !== null) {
- if (PConfig::getPConfigValue($uid, $cat, $k) === '!<unset>!') {
+ if ($this->configCache->getP($uid, $cat, $k) !== null) {
+ if ($this->configCache->getP($uid, $cat, $k) === '!<unset>!') {
return $default_value;
}
- return PConfig::getPConfigValue($uid, $cat, $k);
+ return $this->configCache->getP($uid, $cat, $k);
}
}
if (DBA::isResult($pconfig)) {
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
- PConfig::setPConfigValue($uid, $cat, $k, $val);
+ $this->configCache->setP($uid, $cat, $k, $val);
$this->in_db[$uid][$cat][$k] = true;
return $val;
} else {
- PConfig::setPConfigValue($uid, $cat, $k, '!<unset>!');
+ $this->configCache->setP($uid, $cat, $k, '!<unset>!');
$this->in_db[$uid][$cat][$k] = false;
}
}
+ /**
+ * {@inheritdoc}
+ */
public function set($uid, $cat, $k, $value)
{
// We store our setting values in a string variable.
return true;
}
- PConfig::setPConfigValue($uid, $cat, $k, $value);
+ $this->configCache->setP($uid, $cat, $k, $value);
// manage array value
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
return $result;
}
+ /**
+ * {@inheritdoc}
+ */
public function delete($uid, $cat, $k)
{
- PConfig::deletePConfigValue($uid, $cat, $k);
+ $this->configCache->deleteP($uid, $cat, $k);
if (!empty($this->in_db[$uid][$cat][$k])) {
unset($this->in_db[$uid][$cat][$k]);