public $module_loaded = false;
public $module_class = null;
public $query_string = '';
- public $config = [];
public $page = [];
public $profile;
public $profile_uid;
return true;
}
- /**
- * 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
- *
- * @return string The value of the config entry
- */
- 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;
-
- if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
- $this->config[$uid] = [];
- }
-
- if (!isset($this->config[$uid][$cat]) || !is_array($this->config[$uid][$cat])) {
- $this->config[$uid][$cat] = [];
- }
-
- $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]);
- }
- }
-
/**
* Generates the site's default sender email address
*
* @brief Loads all configuration values of family into a cached storage.
*
* All configuration values of the system are stored in global cache
- * which is available under the global variable $a->config
+ * which is available under the global variable self::$config
*
* @param string $family The category of the configuration value
*
/**
* @brief Deletes the given key from the system configuration.
*
- * Removes the configured value from the stored cache in $a->config
+ * Removes the configured value from the stored cache in Config::$config
* and removes it from the database.
*
* @param string $family The category of the configuration value
* @brief Loads all configuration values into a cached storage.
*
* All configuration values of the system are stored in global cache
- * which is available under the global variable $a->config
+ * which is available under the global variable Config::$config
*
* @param string $cat The category of the configuration values to load
*
/**
* @brief Deletes the given key from the system configuration.
*
- * Removes the configured value from the stored cache in $a->config
+ * Removes the configured value from the stored cache in Config::$config
* and removes it from the database.
*
* @param string $cat The category of the configuration value
* @brief Loads all configuration values of a user's config family into a cached storage.
*
* All configuration values of the given user are stored in global cache
- * which is available under the global variable $a->config[$uid].
+ * which is available under the global variable self::$config[$uid].
*
* @param string $uid The user_id
* @param string $cat The category of the configuration value
* ($family) and a key.
*
* Get a particular user's config value from the given category ($family)
- * and the $key from a cached storage in $a->config[$uid].
+ * and the $key from a cached storage in self::$config[$uid].
*
* @param string $uid The user_id
* @param string $cat The category of the configuration value
/**
* @brief Deletes the given key from the users's configuration.
*
- * Removes the configured value from the stored cache in $a->config[$uid]
+ * Removes the configured value from the stored cache in self::$config[$uid]
* and removes it from the database.
*
* @param string $uid The user_id
<?php
namespace Friendica\Core\Config;
-use Friendica\BaseObject;
+use Friendica\Core\PConfig;
use Friendica\Database\DBA;
/**
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
+class JITPConfigAdapter implements IPConfigAdapter
{
private $in_db;
public function load($uid, $cat)
{
- $a = self::getApp();
-
$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']);
+ PConfig::setPConfigValue($uid, $cat, $k, $pconfig['v']);
$this->in_db[$uid][$cat][$k] = true;
}
} else if ($cat != 'config') {
// Negative caching
- $a->config[$uid][$cat] = "!<unset>!";
+ PConfig::setPConfigValue($uid, $cat, "!<unset>!");
}
DBA::close($pconfigs);
}
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] === '!<unset>!') {
+ if (PConfig::getPConfigValue($uid, $cat) !== null) {
+ if (PConfig::getPConfigValue($uid, $cat) === '!<unset>!') {
return $default_value;
}
}
- if (isset($a->config[$uid][$cat][$k])) {
- if ($a->config[$uid][$cat][$k] === '!<unset>!') {
+ if (PConfig::getPConfigValue($uid, $cat, $k) !== null) {
+ if (PConfig::getPConfigValue($uid, $cat, $k) === '!<unset>!') {
return $default_value;
}
- return $a->config[$uid][$cat][$k];
+ return PConfig::getPConfigValue($uid, $cat, $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);
+ PConfig::setPConfigValue($uid, $cat, $k, $val);
$this->in_db[$uid][$cat][$k] = true;
return $val;
} else {
- self::getApp()->setPConfigValue($uid, $cat, $k, '!<unset>!');
+ PConfig::setPConfigValue($uid, $cat, $k, '!<unset>!');
$this->in_db[$uid][$cat][$k] = false;
return true;
}
- self::getApp()->setPConfigValue($uid, $cat, $k, $value);
+ PConfig::setPConfigValue($uid, $cat, $k, $value);
// manage array value
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
public function delete($uid, $cat, $k)
{
- self::getApp()->deletePConfigValue($uid, $cat, $k);
+ PConfig::deletePConfigValue($uid, $cat, $k);
if (!empty($this->in_db[$uid][$cat][$k])) {
unset($this->in_db[$uid][$cat][$k]);
namespace Friendica\Core\Config;
use Exception;
-use Friendica\BaseObject;
+use Friendica\Core\PConfig;
use Friendica\Database\DBA;
/**
*
* @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
-class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
+class PreloadPConfigAdapter implements IPConfigAdapter
{
private $config_loaded = false;
$pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = DBA::fetch($pconfigs)) {
- self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
+ PConfig::setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
}
DBA::close($pconfigs);
if ($refresh) {
$config = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
if (DBA::isResult($config)) {
- self::getApp()->setPConfigValue($uid, $cat, $k, $config['v']);
+ PConfig::setPConfigValue($uid, $cat, $k, $config['v']);
} else {
- self::getApp()->deletePConfigValue($uid, $cat, $k);
+ PConfig::deletePConfigValue($uid, $cat, $k);
}
}
- $return = self::getApp()->getPConfigValue($uid, $cat, $k, $default_value);
+ $return = PConfig::getPConfigValue($uid, $cat, $k, $default_value);
return $return;
}
// The exception are array values.
$compare_value = !is_array($value) ? (string)$value : $value;
- if (self::getApp()->getPConfigValue($uid, $cat, $k) === $compare_value) {
+ if (PConfig::getPConfigValue($uid, $cat, $k) === $compare_value) {
return true;
}
- self::getApp()->setPConfigValue($uid, $cat, $k, $value);
+ PConfig::setPConfigValue($uid, $cat, $k, $value);
// manage array value
$dbvalue = is_array($value) ? serialize($value) : $value;
$this->load($uid, $cat);
}
- self::getApp()->deletePConfigValue($uid, $cat, $k);
+ PConfig::deletePConfigValue($uid, $cat, $k);
$result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
*/
class PConfig extends BaseObject
{
+ private static $config;
+
/**
* @var \Friendica\Core\Config\IPConfigAdapter
*/
* @brief Loads all configuration values of a user's config family into a cached storage.
*
* All configuration values of the given user are stored in global cache
- * which is available under the global variable $a->config[$uid].
+ * which is available under the global variable self::$config[$uid].
*
* @param string $uid The user_id
* @param string $family The category of the configuration value
* ($family) and a key.
*
* Get a particular user's config value from the given category ($family)
- * and the $key from a cached storage in $a->config[$uid].
+ * and the $key from a cached storage in self::$config[$uid].
*
* @param string $uid The user_id
* @param string $family The category of the configuration value
/**
* @brief Deletes the given key from the users's configuration.
*
- * Removes the configured value from the stored cache in $a->config[$uid]
+ * Removes the configured value from the stored cache in self::$config[$uid]
* and removes it from the database.
*
* @param string $uid The user_id
return self::$adapter->delete($uid, $family, $key);
}
+
+
+ /**
+ * 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
+ *
+ * @return string The value of the config entry
+ */
+ public static function getPConfigValue($uid, $cat, $k = null, $default = null)
+ {
+ $return = $default;
+
+ if (isset(self::$config[$uid][$cat][$k])) {
+ $return = self::$config[$uid][$cat][$k];
+ } elseif ($k == null && isset(self::$config[$uid][$cat])) {
+ $return = self::$config[$uid][$cat];
+ }
+
+ 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 static 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;
+
+ if (!isset(self::$config[$uid]) || !is_array(self::$config[$uid])) {
+ self::$config[$uid] = [];
+ }
+
+ if (!isset(self::$config[$uid][$cat]) || !is_array(self::$config[$uid][$cat])) {
+ self::$config[$uid][$cat] = [];
+ }
+
+ self::$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 static function deletePConfigValue($uid, $cat, $k)
+ {
+ if (isset(self::$config[$uid][$cat][$k])) {
+ unset(self::$config[$uid][$cat][$k]);
+ }
+ }
}