SimpleSAML_Auth_LDAP::makeException PHP Méthode

makeException() private méthode

Convenience method to create an LDAPException as well as log the description.
private makeException ( string $description, $type = null ) : Exception
$description string The exception's description
Résultat Exception
    private function makeException($description, $type = null)
    {
        $errNo = 0x0;
        // Log LDAP code and description, if possible
        if (empty($this->ldap)) {
            SimpleSAML\Logger::error($description);
        } else {
            $errNo = @ldap_errno($this->ldap);
        }
        // Decide exception type and return
        if ($type) {
            if ($errNo !== 0) {
                // Only log real LDAP errors; not success
                SimpleSAML\Logger::error($description . '; cause: \'' . ldap_error($this->ldap) . '\' (0x' . dechex($errNo) . ')');
            } else {
                SimpleSAML\Logger::error($description);
            }
            switch ($type) {
                case ERR_INTERNAL:
                    // 1 - ExInternal
                    return new SimpleSAML_Error_Exception($description, $errNo);
                case ERR_NO_USER:
                    // 2 - ExUserNotFound
                    return new SimpleSAML_Error_UserNotFound($description, $errNo);
                case ERR_WRONG_PW:
                    // 3 - ExInvalidCredential
                    return new SimpleSAML_Error_InvalidCredential($description, $errNo);
                case ERR_AS_DATA_INCONSIST:
                    // 4 - ExAsDataInconsist
                    return new SimpleSAML_Error_AuthSource('ldap', $description);
                case ERR_AS_INTERNAL:
                    // 5 - ExAsInternal
                    return new SimpleSAML_Error_AuthSource('ldap', $description);
            }
        } else {
            if ($errNo !== 0) {
                $description .= '; cause: \'' . ldap_error($this->ldap) . '\' (0x' . dechex($errNo) . ')';
                if (@ldap_get_option($this->ldap, LDAP_OPT_DIAGNOSTIC_MESSAGE, $extendedError) && !empty($extendedError)) {
                    $description .= '; additional: \'' . $extendedError . '\'';
                }
            }
            switch ($errNo) {
                case 0x20:
                    //LDAP_NO_SUCH_OBJECT
                    SimpleSAML\Logger::warning($description);
                    return new SimpleSAML_Error_UserNotFound($description, $errNo);
                case 0x31:
                    //LDAP_INVALID_CREDENTIALS
                    SimpleSAML\Logger::info($description);
                    return new SimpleSAML_Error_InvalidCredential($description, $errNo);
                case -1:
                    //NO_SERVER_CONNECTION
                    SimpleSAML\Logger::error($description);
                    return new SimpleSAML_Error_AuthSource('ldap', $description);
                default:
                    SimpleSAML\Logger::error($description);
                    return new SimpleSAML_Error_AuthSource('ldap', $description);
            }
        }
    }