public function connect(
        $hostname,
        $port = 389,
        $withSSL = false,
        $withTLS = false
    ) {
        if ($withSSL && $withTLS) {
            throw new ConnectionException('Cannot support both TLS & SSL for a given Ldap Connection');
        }

        if (! extension_loaded('ldap') && ! @dl('ldap.' . PHP_SHLIB_SUFFIX)) {
            throw new ConnectionException(
                'You do not have the required ldap-extension installed'
            );
        }

        if ($withSSL) {
            $hostname = 'ldaps://' . $hostname;
        }

        $connection = @ldap_connect($hostname, $port);
        if (false === $connection) {
            throw new ConnectionException('Could not successfully connect to the LDAP server');
        }

        if ($withTLS) {
            if (! (@ldap_start_tls($connection))) {
                $code = @ldap_errno($connection);
                throw new ConnectionException(
                    sprintf('Could not start TLS: Ldap Error Code=%s - %s', $code, ldap_err2str($code))
                );
            }
        }

        return new Connection($connection);
    }