improved setting manager + setting caching
This commit is contained in:
parent
ba41cb3456
commit
471fc1dd79
@ -93,7 +93,7 @@ class SettingManager implements CallbackListener {
|
||||
return $param;
|
||||
}
|
||||
trigger_error('Invalid class param. ' . $param);
|
||||
return (string)$param;
|
||||
return (string) $param;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,16 +131,16 @@ class SettingManager implements CallbackListener {
|
||||
*/
|
||||
private function castSetting($type, $value) {
|
||||
if ($type === self::TYPE_INT) {
|
||||
return (int)$value;
|
||||
return (int) $value;
|
||||
}
|
||||
if ($type === self::TYPE_REAL) {
|
||||
return (float)$value;
|
||||
return (float) $value;
|
||||
}
|
||||
if ($type === self::TYPE_BOOL) {
|
||||
return (bool)$value;
|
||||
return (bool) $value;
|
||||
}
|
||||
if ($type === self::TYPE_STRING) {
|
||||
return (string)$value;
|
||||
return (string) $value;
|
||||
}
|
||||
if ($type === self::TYPE_ARRAY) {
|
||||
return explode($this->arrayDelimiter, $value);
|
||||
@ -178,7 +178,7 @@ class SettingManager implements CallbackListener {
|
||||
* @return bool
|
||||
*/
|
||||
public function initSetting($object, $settingName, $default) {
|
||||
if ($default === null || is_object($default)) {
|
||||
if (is_null($default) || is_object($default)) {
|
||||
return false;
|
||||
}
|
||||
$className = $this->getClassName($object);
|
||||
@ -252,7 +252,7 @@ class SettingManager implements CallbackListener {
|
||||
public function getSetting($object, $settingName, $default = null) {
|
||||
$className = $this->getClassName($object);
|
||||
|
||||
//Check if setting is already in the ram
|
||||
// Check if setting is already in the ram
|
||||
if (isset($this->storedSettings[$className . $settingName])) {
|
||||
return $this->storedSettings[$className . $settingName];
|
||||
}
|
||||
@ -283,7 +283,7 @@ class SettingManager implements CallbackListener {
|
||||
$settingStatement->close();
|
||||
$setting = $this->castSetting($type, $value);
|
||||
|
||||
//Store setting in the ram
|
||||
// Store setting in the ram
|
||||
$this->storedSettings[$className . $settingName] = $setting;
|
||||
return $setting;
|
||||
}
|
||||
@ -298,6 +298,9 @@ class SettingManager implements CallbackListener {
|
||||
*/
|
||||
public function setSetting($object, $settingName, $value) {
|
||||
$className = $this->getClassName($object);
|
||||
|
||||
var_dump($className, $settingName, $value);
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
||||
SET `value` = ?
|
||||
@ -308,8 +311,8 @@ class SettingManager implements CallbackListener {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$value = $this->formatSetting($value);
|
||||
$settingStatement->bind_param('sss', $value, $className, $settingName);
|
||||
$setting = $this->formatSetting($value);
|
||||
$settingStatement->bind_param('sss', $setting, $className, $settingName);
|
||||
$success = $settingStatement->execute();
|
||||
if ($settingStatement->error) {
|
||||
trigger_error($settingStatement->error);
|
||||
@ -318,12 +321,9 @@ class SettingManager implements CallbackListener {
|
||||
}
|
||||
$settingStatement->close();
|
||||
|
||||
//FIXME store changed value
|
||||
if (isset($this->storedSettings[$className . $settingName])) {
|
||||
unset($this->storedSettings[$className . $settingName]);
|
||||
}
|
||||
$this->storedSettings[$className . $settingName] = $value;
|
||||
|
||||
//Trigger settings changed Callback
|
||||
// Trigger settings changed Callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTINGS_CHANGED, $className, $settingName, $value);
|
||||
return $success;
|
||||
}
|
||||
@ -355,6 +355,9 @@ class SettingManager implements CallbackListener {
|
||||
return false;
|
||||
}
|
||||
$settingStatement->close();
|
||||
if (isset($this->storedSettings[$className . $settingName])) {
|
||||
unset($this->storedSettings[$className . $settingName]);
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
@ -384,6 +387,9 @@ class SettingManager implements CallbackListener {
|
||||
return false;
|
||||
}
|
||||
$settingStatement->close();
|
||||
if (isset($this->storedSettings[$className . $settingName])) {
|
||||
unset($this->storedSettings[$className . $settingName]);
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
@ -404,7 +410,7 @@ class SettingManager implements CallbackListener {
|
||||
return null;
|
||||
}
|
||||
$settings = array();
|
||||
while($setting = $result->fetch_object()) {
|
||||
while ($setting = $result->fetch_object()) {
|
||||
$settings[$setting->index] = $setting;
|
||||
}
|
||||
$result->free();
|
||||
@ -426,7 +432,7 @@ class SettingManager implements CallbackListener {
|
||||
return null;
|
||||
}
|
||||
$settings = array();
|
||||
while($setting = $result->fetch_object()) {
|
||||
while ($setting = $result->fetch_object()) {
|
||||
$settings[$setting->index] = $setting;
|
||||
}
|
||||
$result->free();
|
||||
@ -454,6 +460,7 @@ class SettingManager implements CallbackListener {
|
||||
return false;
|
||||
}
|
||||
$settingStatement->close();
|
||||
$this->storedSettings = array();
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user