return true;
}
+
+ /**
+ * @param string $cat Config category
+ * @param string $k Config key
+ * @param mixed $default Default value if it isn't set
+ */
+ public function getConfigValue($cat, $k, $default = null)
+ {
+ $return = $default;
+
+ if ($cat === 'config') {
+ if (isset($this->config[$k])) {
+ $return = $this->config[$k];
+ }
+ } else {
+ if (isset($this->config[$cat][$k])) {
+ $return = $this->config[$cat][$k];
+ }
+ }
+
+ return $return;
+ }
+
+ /**
+ * Sets a value in the config cache. Accepts raw output from the config table
+ *
+ * @param string $cat Config category
+ * @param string $k Config key
+ * @param mixed $v Value to set
+ */
+ public function setConfigValue($cat, $k, $v)
+ {
+ // Only arrays are serialized in database, so we have to unserialize sparingly
+ $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
+
+ if ($cat === 'config') {
+ $this->config[$k] = $value;
+ } else {
+ $this->config[$cat][$k] = $value;
+ }
+ }
+
+ /**
+ * Deletes a value from the config cache
+ *
+ * @param string $cat Config category
+ * @param string $k Config key
+ */
+ public function deleteConfigValue($cat, $k)
+ {
+ if ($cat === 'config') {
+ if (isset($this->config[$k])) {
+ unset($this->config[$k]);
+ }
+ } else {
+ if (isset($this->config[$cat][$k])) {
+ unset($this->config[$cat][$k]);
+ }
+ }
+ }
+
+
+ /**
+ * Retrieves a value from the user config cache
+ *
+ * @param int $uid User Id
+ * @param string $cat Config category
+ * @param string $k Config key
+ * @param mixed $default Default value if key isn't set
+ */
+ public function getPConfigValue($uid, $cat, $k, $default = null)
+ {
+ $return = $default;
+
+ if (isset($this->config[$uid][$cat][$k])) {
+ $return = $this->config[$uid][$cat][$k];
+ }
+
+ return $return;
+ }
+
+ /**
+ * Sets a value in the user config cache
+ *
+ * Accepts raw output from the pconfig table
+ *
+ * @param int $uid User Id
+ * @param string $cat Config category
+ * @param string $k Config key
+ * @param mixed $v Value to set
+ */
+ public function setPConfigValue($uid, $cat, $k, $v)
+ {
+ // Only arrays are serialized in database, so we have to unserialize sparingly
+ $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
+
+ $this->config[$uid][$cat][$k] = $value;
+ }
+
+ /**
+ * Deletes a value from the user config cache
+ *
+ * @param int $uid User Id
+ * @param string $cat Config category
+ * @param string $k Config key
+ */
+ public function deletePConfigValue($uid, $cat, $k)
+ {
+ if (isset($this->config[$uid][$cat][$k])) {
+ unset($this->config[$uid][$cat][$k]);
+ }
+ }
}
public static function init()
{
- $a = self::getApp();
-
- if (isset($a->config['system']['config_adapter']) && $a->config['system']['config_adapter'] == 'preload') {
+ if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
self::$adapter = new Config\PreloadConfigAdapter();
} else {
self::$adapter = new Config\JITConfigAdapter();
require_once 'include/dba.php';
/**
- * JustInTime ConfigAdapter
+ * JustInTime Configuration Adapter
*
* Default Config Adapter. Provides the best performance for pages loading few configuration variables.
*
return;
}
- $a = self::getApp();
-
$configs = dba::select('config', ['v', 'k'], ['cat' => $cat]);
while ($config = dba::fetch($configs)) {
$k = $config['k'];
- if ($cat === 'config') {
- $a->config[$k] = $config['v'];
- } else {
- $a->config[$cat][$k] = $config['v'];
- self::$cache[$cat][$k] = $config['v'];
- self::$in_db[$cat][$k] = true;
+
+ self::getApp()->setConfigValue($cat, $k, $config['v']);
+
+ if ($cat !== 'config') {
+ $this->cache[$cat][$k] = $config['v'];
+ $this->in_db[$cat][$k] = true;
}
}
dba::close($configs);
return true;
}
- if ($cat === 'config') {
- $a->config[$k] = $dbvalue;
- } elseif ($cat != 'system') {
- $a->config[$cat][$k] = $dbvalue;
- }
+ self::getApp()->setConfigValue($cat, $k, $value);
// Assign the just added value to the cache
$this->cache[$cat][$k] = $dbvalue;
require_once 'include/dba.php';
/**
- * JustInTime PConfigAdapter
+ * JustInTime User Configuration Adapter
*
* Default PConfig Adapter. Provides the best performance for pages loading few configuration variables.
*
if (DBM::is_result($pconfigs)) {
while ($pconfig = dba::fetch($pconfigs)) {
$k = $pconfig['k'];
- $a->config[$uid][$cat][$k] = $pconfig['v'];
+
+ self::getApp()->setPConfigValue($uid, $cat, $k, $pconfig['v']);
+
$this->in_db[$uid][$cat][$k] = true;
}
} else if ($cat != 'config') {
$pconfig = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
if (DBM::is_result($pconfig)) {
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
- $a->config[$uid][$cat][$k] = $val;
+
+ self::getApp()->setPConfigValue($uid, $cat, $k, $val);
+
$this->in_db[$uid][$cat][$k] = true;
return $val;
} else {
- $a->config[$uid][$cat][$k] = '!<unset>!';
+ self::getApp()->setPConfigValue($uid, $cat, $k, '!<unset>!');
+
$this->in_db[$uid][$cat][$k] = false;
return $default_value;
public function set($uid, $cat, $k, $value)
{
- $a = self::getApp();
-
// 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;
}
- $a->config[$uid][$cat][$k] = $dbvalue;
+ self::getApp()->setPConfigValue($uid, $cat, $k, $value);
// manage array value
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
public function delete($uid, $cat, $k)
{
- $a = self::getApp();
+ self::getApp()->deletePConfigValue($uid, $cat, $k);
- if (!empty($a->config[$uid][$cat][$k])) {
- unset($a->config[$uid][$cat][$k]);
+ if (!empty($this->in_db[$uid][$cat][$k])) {
unset($this->in_db[$uid][$cat][$k]);
}
require_once 'include/dba.php';\r
\r
/**\r
- * Preload ConfigAdapter\r
+ * Preload Configuration Adapter\r
*\r
- * Minimize the number of database queries to retrieve configuration values at the cost of memory.\r
+ * Minimizes the number of database queries to retrieve configuration values at the cost of memory.\r
*\r
* @author Hypolite Petovan <mrpetovan@gmail.com>\r
*/\r
\r
$configs = dba::select('config', ['cat', 'v', 'k']);\r
while ($config = dba::fetch($configs)) {\r
- $this->setPreloadedValue($config['cat'], $config['k'], $config['v']);\r
+ self::getApp()->setConfigValue($config['cat'], $config['k'], $config['v']);\r
}\r
dba::close($configs);\r
\r
if ($refresh) {\r
$config = dba::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);\r
if (DBM::is_result($config)) {\r
- $this->setPreloadedValue($cat, $k, $config['v']);\r
+ self::getApp()->setConfigValue($cat, $k, $config['v']);\r
}\r
}\r
\r
- $return = $this->getPreloadedValue($cat, $k, $default_value);\r
+ $return = self::getApp()->getConfigValue($cat, $k, $default_value);\r
\r
return $return;\r
}\r
// The exception are array values.\r
$compare_value = !is_array($value) ? (string)$value : $value;\r
\r
- if ($this->getPreloadedValue($cat, $k) === $compare_value) {\r
+ if (self::getApp()->getConfigValue($cat, $k) === $compare_value) {\r
return true;\r
}\r
\r
- $this->setPreloadedValue($cat, $k, $value);\r
+ self::getApp()->setConfigValue($cat, $k, $value);\r
\r
// manage array value\r
$dbvalue = is_array($value) ? serialize($value) : $value;\r
\r
public function delete($cat, $k)\r
{\r
- $this->deletePreloadedValue($cat, $k);\r
+ self::getApp()->deleteConfigValue($cat, $k);\r
\r
$result = dba::delete('config', ['cat' => $cat, 'k' => $k]);\r
\r
return $result;\r
}\r
-\r
- /**\r
- * Retrieves a preloaded value from the App config cache\r
- *\r
- * @param string $cat\r
- * @param string $k\r
- * @param mixed $default\r
- */\r
- private function getPreloadedValue($cat, $k, $default = null)\r
- {\r
- $a = self::getApp();\r
-\r
- $return = $default;\r
-\r
- if ($cat === 'config') {\r
- if (isset($a->config[$k])) {\r
- $return = $a->config[$k];\r
- }\r
- } else {\r
- if (isset($a->config[$cat][$k])) {\r
- $return = $a->config[$cat][$k];\r
- }\r
- }\r
-\r
- return $return;\r
- }\r
-\r
- /**\r
- * Sets a preloaded value in the App config cache\r
- *\r
- * Accepts raw output from the config table\r
- *\r
- * @param string $cat\r
- * @param string $k\r
- * @param mixed $v\r
- */\r
- private function setPreloadedValue($cat, $k, $v)\r
- {\r
- $a = self::getApp();\r
-\r
- // Only arrays are serialized in database, so we have to unserialize sparingly\r
- $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;\r
-\r
- if ($cat === 'config') {\r
- $a->config[$k] = $value;\r
- } else {\r
- $a->config[$cat][$k] = $value;\r
- }\r
- }\r
-\r
- /**\r
- * Deletes a preloaded value from the App config cache\r
- *\r
- * @param string $cat\r
- * @param string $k\r
- */\r
- private function deletePreloadedValue($cat, $k)\r
- {\r
- $a = self::getApp();\r
-\r
- if ($cat === 'config') {\r
- if (isset($a->config[$k])) {\r
- unset($a->config[$k]);\r
- }\r
- } else {\r
- if (isset($a->config[$cat][$k])) {\r
- unset($a->config[$cat][$k]);\r
- }\r
- }\r
- }\r
}\r
require_once 'include/dba.php';\r
\r
/**\r
- * Preload PConfigAdapter\r
+ * Preload User Configuration Adapter\r
*\r
- * Minimize the number of database queries to retrieve configuration values at the cost of memory.\r
+ * Minimizes the number of database queries to retrieve configuration values at the cost of memory.\r
*\r
* @author Hypolite Petovan <mrpetovan@gmail.com>\r
*/\r
\r
$pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);\r
while ($pconfig = dba::fetch($pconfigs)) {\r
- $this->setPreloadedValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);\r
+ self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);\r
}\r
dba::close($pconfigs);\r
\r
if ($refresh) {\r
$config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);\r
if (DBM::is_result($config)) {\r
- $this->setPreloadedValue($uid, $cat, $k, $config['v']);\r
+ self::getApp()->setPConfigValue($uid, $cat, $k, $config['v']);\r
} else {\r
- $this->deletePreloadedValue($uid, $cat, $k);\r
+ self::getApp()->deletePConfigValue($uid, $cat, $k);\r
}\r
}\r
\r
- $return = $this->getPreloadedValue($uid, $cat, $k, $default_value);\r
+ $return = self::getApp()->getPConfigValue($uid, $cat, $k, $default_value);\r
\r
return $return;\r
}\r
// The exception are array values.\r
$compare_value = !is_array($value) ? (string)$value : $value;\r
\r
- if ($this->getPreloadedValue($uid, $cat, $k) === $compare_value) {\r
+ if (self::getApp()->getPConfigValue($uid, $cat, $k) === $compare_value) {\r
return true;\r
}\r
\r
- $this->setPreloadedValue($uid, $cat, $k, $value);\r
+ self::getApp()->setPConfigValue($uid, $cat, $k, $value);\r
\r
// manage array value\r
$dbvalue = is_array($value) ? serialize($value) : $value;\r
\r
public function delete($uid, $cat, $k)\r
{\r
- $this->deletePreloadedValue($uid, $cat, $k);\r
+ self::getApp()->deletePConfigValue($uid, $cat, $k);\r
\r
$result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);\r
\r
return $result;\r
}\r
-\r
-\r
- /**\r
- * Retrieves a preloaded value from the App user config cache\r
- *\r
- * @param int $uid\r
- * @param string $cat\r
- * @param string $k\r
- * @param mixed $default\r
- */\r
- private function getPreloadedValue($uid, $cat, $k, $default = null)\r
- {\r
- $a = self::getApp();\r
-\r
- $return = $default;\r
-\r
- if (isset($a->config[$uid][$cat][$k])) {\r
- $return = $a->config[$uid][$cat][$k];\r
- }\r
-\r
- return $return;\r
- }\r
-\r
- /**\r
- * Sets a preloaded value in the App user config cache\r
- *\r
- * Accepts raw output from the pconfig table\r
- *\r
- * @param int $uid\r
- * @param string $cat\r
- * @param string $k\r
- * @param mixed $v\r
- */\r
- private function setPreloadedValue($uid, $cat, $k, $v)\r
- {\r
- $a = self::getApp();\r
-\r
- // Only arrays are serialized in database, so we have to unserialize sparingly\r
- $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;\r
-\r
- $a->config[$uid][$cat][$k] = $value;\r
- }\r
-\r
- /**\r
- * Deletes a preloaded value from the App user config cache\r
- *\r
- * @param int $uid\r
- * @param string $cat\r
- * @param string $k\r
- */\r
- private function deletePreloadedValue($uid, $cat, $k)\r
- {\r
- $a = self::getApp();\r
-\r
- if (isset($a->config[$uid][$cat][$k])) {\r
- unset($a->config[$uid][$cat][$k]);\r
- }\r
- }\r
}\r