From dee0c38ff46e1e53a84679a96da833c67c89ae3a Mon Sep 17 00:00:00 2001 From: Menno Dekker Date: Tue, 2 Apr 2013 10:12:41 +0200 Subject: [PATCH] dev: moved getconfig to plugin api as getconfigkey with optional default value when not found --- application/core/LSYii_Application.php | 5 +++-- application/core/plugins/Authdb/Authdb.php | 2 +- .../core/plugins/Authwebserver/Authwebserver.php | 8 ++++---- .../libraries/PluginManager/LimesurveyApi.php | 13 +++++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/application/core/LSYii_Application.php b/application/core/LSYii_Application.php index d733ba95fe7..d87f485aa18 100644 --- a/application/core/LSYii_Application.php +++ b/application/core/LSYii_Application.php @@ -238,11 +238,12 @@ public function loadConfig($file) * * @access public * @param string $name + * @param type $default Value to return when not found, default is false * @return mixed */ - public function getConfig($name) + public function getConfig($name, $default = false) { - return isset($this->config[$name]) ? $this->config[$name] : false; + return isset($this->config[$name]) ? $this->config[$name] : $default; } diff --git a/application/core/plugins/Authdb/Authdb.php b/application/core/plugins/Authdb/Authdb.php index cfd7b00b82c..8f6d7375cf3 100644 --- a/application/core/plugins/Authdb/Authdb.php +++ b/application/core/plugins/Authdb/Authdb.php @@ -96,7 +96,7 @@ public function newUserSession(PluginEvent $event) return; } - if ($onepass != '' && Yii::app()->getConfig("use_one_time_passwords") && md5($onepass) == $user->one_time_pw) + if ($onepass != '' && $this->api->getConfigKey('use_one_time_passwords') && md5($onepass) == $user->one_time_pw) { $user->one_time_pw=''; $user->save(); diff --git a/application/core/plugins/Authwebserver/Authwebserver.php b/application/core/plugins/Authwebserver/Authwebserver.php index 5021b075965..35455a0b0cf 100644 --- a/application/core/plugins/Authwebserver/Authwebserver.php +++ b/application/core/plugins/Authwebserver/Authwebserver.php @@ -35,7 +35,7 @@ public function beforeLogin(PluginEvent $event) $sUser = substr($sUser, strrpos($sUser, "\\")+1); } - $aUserMappings=Yii::app()->getConfig("auth_webserver_user_map"); + $aUserMappings=$this->api->getConfigKey('auth_webserver_user_map', array()); if (isset($aUserMappings[$sUser])) { $sUser = $aUserMappings[$sUser]; @@ -63,9 +63,9 @@ public function newUserSession(PluginEvent $event) // describing the default profile for this user $aUserProfile = hook_get_auth_webserver_profile($sUser); } - elseif (Yii::app()->getConfig("auth_webserver_autocreate_user")) + elseif ($this->api->getConfigKey('auth_webserver_autocreate_user')) { - $aUserProfile=Yii::app()->getConfig("auth_webserver_autocreate_profile"); + $aUserProfile=$this->api->getConfigKey('auth_webserver_autocreate_profile'); } } else { $identity->id = $oUser->uid; @@ -76,7 +76,7 @@ public function newUserSession(PluginEvent $event) - if (Yii::app()->getConfig("auth_webserver_autocreate_user") && isset($aUserProfile) && is_null($oUser)) + if ($this->api->getConfigKey('auth_webserver_autocreate_user') && isset($aUserProfile) && is_null($oUser)) { // user doesn't exist but auto-create user is set $oUser=new User; $oUser->users_name=$sUser; diff --git a/application/libraries/PluginManager/LimesurveyApi.php b/application/libraries/PluginManager/LimesurveyApi.php index be23a4ca775..1433ca2c829 100644 --- a/application/libraries/PluginManager/LimesurveyApi.php +++ b/application/libraries/PluginManager/LimesurveyApi.php @@ -6,6 +6,19 @@ */ class LimesurveyApi { + /** + * Read a key from the application config, and when not set + * return the default value + * + * @param string $key The key to search for in the application config + * @param mixed $defaultValue Value to return when not found, default is false + * @return mixed + */ + public function getConfigKey($key, $defaultValue = false) + { + return App()->getConfig($key, $defaultValue); + } + /** * Generates the real table name from plugin and tablename. * @param iPlugin $plugin