*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class JITConfigAdapter implements IConfigAdapter
+class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapter
{
private $cache;
private $in_db;
/**
* @var IConfigCache The config cache of this driver
*/
- private $config;
+ private $configCache;
/**
- * @param IConfigCache $config The config cache of this driver
+ * @param IConfigCache $configCache The config cache of this driver
*/
- public function __construct($config)
+ public function __construct(IConfigCache $configCache)
{
- $this->config = $config;
+ $this->configCache = $configCache;
+ $this->connected = DBA::connected();
}
+ /**
+ * {@inheritdoc}
+ */
public function load($cat = "config")
{
+ if (!$this->isConnected()) {
+ return;
+ }
+
// We don't preload "system" anymore.
// This reduces the number of database reads a lot.
if ($cat === 'system') {
while ($config = DBA::fetch($configs)) {
$k = $config['k'];
- $this->config->set($cat, $k, $config['v']);
+ $this->configCache->set($cat, $k, $config['v']);
if ($cat !== 'config') {
$this->cache[$cat][$k] = $config['v'];
DBA::close($configs);
}
+ /**
+ * {@inheritdoc}
+ */
public function get($cat, $k, $default_value = null, $refresh = false)
{
+ if (!$this->isConnected()) {
+ return $default_value;
+ }
+
if (!$refresh) {
// Do we have the cached value? Then return it
if (isset($this->cache[$cat][$k])) {
$this->cache[$cat][$k] = $value;
$this->in_db[$cat][$k] = true;
return $value;
- } elseif ($this->config->get($cat, $k) !== null) {
+ } elseif ($this->configCache->get($cat, $k) !== null) {
// Assign the value (mostly) from config/local.config.php file to the cache
- $this->cache[$cat][$k] = $this->config->get($cat, $k);
+ $this->cache[$cat][$k] = $this->configCache->get($cat, $k);
$this->in_db[$cat][$k] = false;
- return $this->config->get($cat, $k);
- } elseif ($this->config->get('config', $k) !== null) {
+ return $this->configCache->get($cat, $k);
+ } elseif ($this->configCache->get('config', $k) !== null) {
// Assign the value (mostly) from config/local.config.php file to the cache
- $this->cache[$k] = $this->config->get('config', $k);
+ $this->cache[$k] = $this->configCache->get('config', $k);
$this->in_db[$k] = false;
- return $this->config->get('config', $k);
+ return $this->configCache->get('config', $k);
}
$this->cache[$cat][$k] = '!<unset>!';
return $default_value;
}
+ /**
+ * {@inheritdoc}
+ */
public function set($cat, $k, $value)
{
+ if (!$this->isConnected()) {
+ return false;
+ }
+
// We store our setting values in a string variable.
// So we have to do the conversion here so that the compare below works.
// The exception are array values.
return true;
}
- $this->config->set($cat, $k, $value);
+ $this->configCache->set($cat, $k, $value);
// Assign the just added value to the cache
$this->cache[$cat][$k] = $dbvalue;
return $result;
}
+ /**
+ * {@inheritdoc}
+ */
public function delete($cat, $k)
{
+ if (!$this->isConnected()) {
+ return false;
+ }
+
if (isset($this->cache[$cat][$k])) {
unset($this->cache[$cat][$k]);
unset($this->in_db[$cat][$k]);