Skip to content

Commit

Permalink
dev: moved getconfig to plugin api as getconfigkey with optional defa…
Browse files Browse the repository at this point in the history
…ult value when not found
  • Loading branch information
mennodekker committed Apr 2, 2013
1 parent 8d5c09e commit dee0c38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions application/core/LSYii_Application.php
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion application/core/plugins/Authdb/Authdb.php
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions application/core/plugins/Authwebserver/Authwebserver.php
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions application/libraries/PluginManager/LimesurveyApi.php
Expand Up @@ -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
Expand Down

0 comments on commit dee0c38

Please sign in to comment.