本文整理汇总了PHP中Net_LDAP2::setErrorHandling方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_LDAP2::setErrorHandling方法的具体用法?PHP Net_LDAP2::setErrorHandling怎么用?PHP Net_LDAP2::setErrorHandling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_LDAP2
的用法示例。
在下文中一共展示了Net_LDAP2::setErrorHandling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LdapInvalidCredentialsException
function get_ldap_connection($config = null)
{
if ($config == null) {
$config = $this->ldap_config;
}
$config_id = crc32(serialize($config));
if (array_key_exists($config_id, self::$ldap_connections)) {
$ldap = self::$ldap_connections[$config_id];
} else {
//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->setErrorHandling(PEAR_ERROR_RETURN);
$err = $ldap->bind();
if (Net_LDAP2::isError($err)) {
// if we were called with a config, assume caller will handle
// incorrect username/password (LDAP_INVALID_CREDENTIALS)
if (isset($config) && $err->getCode() == 0x31) {
throw new LdapInvalidCredentialsException('Could not connect to LDAP server: ' . $err->getMessage());
}
throw new Exception('Could not connect to LDAP server: ' . $err->getMessage());
}
$c = common_memcache();
if (!empty($c)) {
$cacheObj = new MemcacheSchemaCache(array('c' => $c, 'cacheKey' => common_cache_key('ldap_schema:' . $config_id)));
$ldap->registerSchemaCache($cacheObj);
}
self::$ldap_connections[$config_id] = $ldap;
}
return $ldap;
}
示例2: Exception
function ldap_get_connection($config = null)
{
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(isset($config) ? $config : $this->ldap_get_config());
$ldap->setErrorHandling(PEAR_ERROR_RETURN);
$err = $ldap->bind();
if (Net_LDAP2::isError($err)) {
// if we were called with a config, assume caller will handle
// incorrect username/password (LDAP_INVALID_CREDENTIALS)
if (isset($config) && $err->getCode() == 0x31) {
return null;
}
throw new Exception('Could not connect to LDAP server: ' . $err->getMessage());
return false;
}
if ($config == null) {
$this->default_ldap = $ldap;
}
return $ldap;
}