protected function buildUri(array $parts)
    {
        $uri = 
            ($parts['scheme'] ? "{$parts['scheme']}:" : '') . 
            ($parts['user'] || $parts['host'] ? '//' : '') . 
            ($parts['user'] ? "{$parts['user']}" : '') . 
            ($parts['user'] && $parts['pass'] ? ":{$parts['pass']}" : '') . 
            ($parts['user'] ? '@' : '') . 
            ($parts['host'] ? "{$parts['host']}" : '') . 
            ($parts['port'] ? ":{$parts['port']}" : '');
            
        $uri .=
            ($uri && $parts['path'] && $parts['path'][0] !== '/' ? '/' : '') .
            ($parts['path'] ? "{$parts['path']}" : '') . 
            ($parts['query'] ? "?{$parts['query']}" : '') . 
            ($parts['fragment'] ? "#{$parts['fragment']}" : '');
            
        return $uri;
    }