private static function aggregateUriFromServer($server)
    {
        $uri = new Uri();

        $scheme = 'http';
        $uri = $uri->withScheme($scheme);

        if (isset($server['SERVER_NAME'])) {
            $uri = $uri->withHost($server['SERVER_NAME']);
        }

        if (isset($server['SERVER_PORT'])) {
            $uri = $uri->withPort((int)$server['SERVER_PORT']);
        }

        if (isset($server['REQUEST_URI'])) {
            $q = explode('?', $server['REQUEST_URI']);

            if (isset($q[0])) {
                $uri = $uri->withPath($q[0]);
            }
        }

        if (isset($server['QUERY_STRING'])) {
            $uri = $uri->withQuery($server['QUERY_STRING']);
        }

        return $uri;
    }