public function toString()
    {
        $result = "";

        if (!empty($this->scheme)) {
            $result .= "{$this->scheme}://";
        }

        if (!empty($this->user)) {
            $result .= !empty($this->pass)
                ? "{$this->user}:{$this->pass}@"
                : "{$this->user}@";
        }

        $result .= $this->host;

        if (!empty($this->port) && (isset($this->portMap[$this->scheme]) && $this->port != $this->portMap[$this->scheme])) {
            $result .= ":{$this->port}";
        }

        $result .= $this->path;

        $qs = $this->query->toString();
        if (!empty($qs)) {
            $result .= "?{$qs}";
        }

        if (!empty($this->fragment)) {
            $result .= "#{$this->fragment}";
        }

        return $result;
    }