diff options
author | brantje <brantje@gmail.com> | 2016-12-30 18:56:57 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-12-30 18:59:48 +0300 |
commit | 863d7c49859fe7bcf049b86c73b00795e97439ca (patch) | |
tree | 49f57b18e839fe810a2cd09c12c0a9087ca800c1 /lib | |
parent | 3bbaa6296b4f8f9b8d78db45fd8469825f72ac99 (diff) |
Add test for Settings, improve SettingsService
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/SettingsService.php | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 8c9d9d67..ae486373 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -46,14 +46,6 @@ class SettingsService { $this->userId = $UserId; $this->config = $config; $this->appName = $AppName; - } - - /** - * Get all app settings - * - * @return array - */ - public function getAppSettings() { $this->settings = array( 'link_sharing_enabled' => intval($this->config->getAppValue('passman', 'link_sharing_enabled', 1)), 'user_sharing_enabled' => intval($this->config->getAppValue('passman', 'user_sharing_enabled', 1)), @@ -63,6 +55,14 @@ class SettingsService { 'disable_contextmenu' => intval($this->config->getAppValue('passman', 'disable_contextmenu', 1)), 'settings_loaded' => 1 ); + } + + /** + * Get all app settings + * + * @return array + */ + public function getAppSettings() { return $this->settings; } @@ -74,9 +74,13 @@ class SettingsService { * @return mixed */ public function getAppSetting($key, $default_value = null) { - $value = $this->config->getAppValue('passman', $key, $default_value); - if (in_array($key, $this->numeric_settings)) { - $value = intval($value); + if (isset($this->settings[$key])) { + $value = $this->settings[$key]; + if (in_array($key, $this->numeric_settings)) { + $value = intval($value); + } + } else { + $value = $this->config->getAppValue('passman', $key, $default_value); } return $value; } @@ -88,6 +92,7 @@ class SettingsService { * @param $value mixed Value of the setting */ public function setAppSetting($key, $value) { + $this->settings[$key] = $value; $this->config->setAppValue('passman', $key, $value); } @@ -98,7 +103,7 @@ class SettingsService { * @param $value mixed Value of the setting */ - public function setUserSetting($key, $value){ + public function setUserSetting($key, $value) { return $this->config->setUserValue($this->userId, $this->appName, $key, $value); } @@ -108,8 +113,8 @@ class SettingsService { * @param $setting * @return bool */ - public function isEnabled($setting){ - $value = intval($this->config->getAppValue('passman', $setting, false)); + public function isEnabled($setting) { + $value = intval($this->getAppSetting($setting, false)); return ($value === 1); } }
\ No newline at end of file |