X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FConfig%2FJITPConfigAdapter.php;h=b1a15601cc4cdaa28efbd7687c7c0aeb65e65097;hb=a0b14a46cb83b93ea5f42437bc78aafd20eec70c;hp=ce9c5b6462d95d58a346620a6474f1eba5568408;hpb=88353ce56f0e5da6352af2d999a58bd0c9b375f7;p=friendica.git diff --git a/src/Core/Config/JITPConfigAdapter.php b/src/Core/Config/JITPConfigAdapter.php index ce9c5b6462..b1a15601cc 100644 --- a/src/Core/Config/JITPConfigAdapter.php +++ b/src/Core/Config/JITPConfigAdapter.php @@ -1,74 +1,86 @@ + * @author Hypolite Petovan */ -class JITPConfigAdapter extends BaseObject implements IPConfigAdapter +class JITPConfigAdapter implements IPConfigAdapter { private $in_db; - public function load($uid, $cat) + /** + * The config cache of this adapter + * @var IPConfigCache + */ + private $configCache; + + /** + * @param IPConfigCache $configCache The config cache of this adapter + */ + public function __construct(IPConfigCache $configCache) { - $a = self::getApp(); + $this->configCache = $configCache; + } - $pconfigs = dba::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]); - if (DBM::is_result($pconfigs)) { - while ($pconfig = dba::fetch($pconfigs)) { + /** + * {@inheritdoc} + */ + public function load($uid, $cat) + { + $pconfigs = DBA::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]); + if (DBA::isResult($pconfigs)) { + while ($pconfig = DBA::fetch($pconfigs)) { $k = $pconfig['k']; - self::getApp()->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 - $a->config[$uid][$cat] = "!!"; + $this->configCache->setP($uid, $cat, null, "!!"); } - dba::close($pconfigs); + DBA::close($pconfigs); } + /** + * {@inheritdoc} + */ public function get($uid, $cat, $k, $default_value = null, $refresh = false) { - $a = self::getApp(); - if (!$refresh) { // Looking if the whole family isn't set - if (isset($a->config[$uid][$cat])) { - if ($a->config[$uid][$cat] === '!!') { + if ($this->configCache->getP($uid, $cat) !== null) { + if ($this->configCache->getP($uid, $cat) === '!!') { return $default_value; } } - if (isset($a->config[$uid][$cat][$k])) { - if ($a->config[$uid][$cat][$k] === '!!') { + if ($this->configCache->getP($uid, $cat, $k) !== null) { + if ($this->configCache->getP($uid, $cat, $k) === '!!') { return $default_value; } - return $a->config[$uid][$cat][$k]; + return $this->configCache->getP($uid, $cat, $k); } } - $pconfig = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]); - if (DBM::is_result($pconfig)) { + $pconfig = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]); + if (DBA::isResult($pconfig)) { $val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']); - self::getApp()->setPConfigValue($uid, $cat, $k, $val); + $this->configCache->setP($uid, $cat, $k, $val); $this->in_db[$uid][$cat][$k] = true; return $val; } else { - self::getApp()->setPConfigValue($uid, $cat, $k, '!!'); + $this->configCache->setP($uid, $cat, $k, '!!'); $this->in_db[$uid][$cat][$k] = false; @@ -76,6 +88,9 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter } } + /** + * {@inheritdoc} + */ public function set($uid, $cat, $k, $value) { // We store our setting values in a string variable. @@ -89,30 +104,32 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter return true; } - self::getApp()->setPConfigValue($uid, $cat, $k, $value); + $this->configCache->setP($uid, $cat, $k, $value); // manage array value $dbvalue = (is_array($value) ? serialize($value) : $dbvalue); - $result = dba::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true); + $result = DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true); if ($result) { $this->in_db[$uid][$cat][$k] = true; - return $value; } return $result; } + /** + * {@inheritdoc} + */ public function delete($uid, $cat, $k) { - self::getApp()->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]); } - $result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]); + $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]); return $result; }