diff options
author | Craig Andrews <candrews@integralblue.com> | 2009-11-18 16:58:06 -0500 |
---|---|---|
committer | Craig Andrews <candrews@integralblue.com> | 2009-11-18 16:58:06 -0500 |
commit | a00141a180d54cbcc244e0157c72f53ac53779b3 (patch) | |
tree | 34f6b25525f7f8e43189fe4ec91468a8d922d6fd | |
parent | 6d69d89cfea15e2a626cdf9378b75a3dfae65d4a (diff) |
You cannot use static that way - using another approach to save reuse the default ldap connection
-rw-r--r-- | plugins/LdapAuthentication/LdapAuthenticationPlugin.php | 11 | ||||
-rw-r--r-- | plugins/LdapAuthorization/LdapAuthorizationPlugin.php | 11 |
2 files changed, 8 insertions, 14 deletions
diff --git a/plugins/LdapAuthentication/LdapAuthenticationPlugin.php b/plugins/LdapAuthentication/LdapAuthenticationPlugin.php index 9e089485c..8caacff46 100644 --- a/plugins/LdapAuthentication/LdapAuthenticationPlugin.php +++ b/plugins/LdapAuthentication/LdapAuthenticationPlugin.php @@ -159,24 +159,21 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin } function ldap_get_connection($config = null){ - if($config == null){ - static $ldap = null; - if($ldap != null){ - return $ldap; - } - $config = $this->ldap_get_config(); + if($config == null && isset($this->default_ldap)){ + return $this->default_ldap; } //cannot use Net_LDAP2::connect() as StatusNet uses //PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError'); //PEAR handling can be overridden on instance objects, so we do that. - $ldap = new Net_LDAP2($config); + $ldap = new Net_LDAP2(isset($config)?$config:$this->ldap_get_config()); $ldap->setErrorHandling(PEAR_ERROR_RETURN); $err=$ldap->bind(); if (Net_LDAP2::isError($err)) { common_log(LOG_WARNING, 'Could not connect to LDAP server: '.$err->getMessage()); return false; } + if($config == null) $this->default_ldap=$ldap; return $ldap; } diff --git a/plugins/LdapAuthorization/LdapAuthorizationPlugin.php b/plugins/LdapAuthorization/LdapAuthorizationPlugin.php index 91a343f40..5e759c379 100644 --- a/plugins/LdapAuthorization/LdapAuthorizationPlugin.php +++ b/plugins/LdapAuthorization/LdapAuthorizationPlugin.php @@ -158,24 +158,21 @@ class LdapAuthorizationPlugin extends AuthorizationPlugin //-----the below function were copied from LDAPAuthenticationPlugin. They will be moved to a utility class soon.----\\ function ldap_get_connection($config = null){ - if($config == null){ - static $ldap = null; - if($ldap != null){ - return $ldap; - } - $config = $this->ldap_get_config(); + if($config == null && isset($this->default_ldap)){ + return $this->default_ldap; } //cannot use Net_LDAP2::connect() as StatusNet uses //PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError'); //PEAR handling can be overridden on instance objects, so we do that. - $ldap = new Net_LDAP2($config); + $ldap = new Net_LDAP2(isset($config)?$config:$this->ldap_get_config()); $ldap->setErrorHandling(PEAR_ERROR_RETURN); $err=$ldap->bind(); if (Net_LDAP2::isError($err)) { common_log(LOG_WARNING, 'Could not connect to LDAP server: '.$err->getMessage()); return false; } + if($config == null) $this->default_ldap=$ldap; return $ldap; } |