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