getResource(); } $message = ''; if ($code === 0) $code = Zend_Ldap_Exception::getLdapCode($resource); if ($code) $message .= '0x' . dechex($code); if (is_resource($resource)) { /* The various error retrieval functions can return * different things so we just try to collect what we * can and eliminate dupes. */ $estr1 = @ldap_error($resource); if ($code !== 0 && $estr1 === 'Success') $estr1 = @ldap_err2str($code); if ($estr1 !== $str) $this->_append($message, $estr1); @ldap_get_option($resource, LDAP_OPT_ERROR_STRING, $estr2); if ($estr2 !== $str && $estr2 !== $estr1) $this->_append($message, $estr2); } $this->_append($message, $str); parent::__construct($message, $code); } private function _append(&$message, $estr) { if ($estr) { if ($message) $message .= ': '; $message .= $estr; } } /** * @param mixed $ldap A Zend_Ldap object or raw LDAP context resource * @return int The current error code for the resource */ public static function getLdapCode($ldap) { $resource = null; if (is_resource($ldap)) { $resource = $ldap; } else if (is_object($ldap)) { $resource = $ldap->getResource(); } if (is_resource($resource)) { $ret = @ldap_get_option($resource, LDAP_OPT_ERROR_NUMBER, $err); if ($ret === true) { if ($err <= -1 && $err >= -17) { /* For some reason draft-ietf-ldapext-ldap-c-api-xx.txt error * codes in OpenLDAP are negative values from -1 to -17. */ $err = Zend_Ldap_Exception::LDAP_SERVER_DOWN + (-$err - 1); } return $err; } } return 0; } /** * @param string $message An informtive exception message * */ public function setMessage($message) { $this->_message = $message; } /** * @return int The current error code for this exception */ public function getErrorCode() { return $this->getCode(); } }