private function getPathFromUri($uri)
    {
        $uriParser = new UriParser($uri);
        // Prepare uri
        $uriParser->encode();
        $uri = $uriParser->stripFragment();
        if (strpos($uri, '/') === 0) {
            // URI is already an path
            return $uri;
        }
        if (!$uriParser->validate()) {
            throw new \InvalidArgumentException('Invalid URI');
        }
        $path = (($path = parse_url($uri, PHP_URL_PATH)) === null) ? '/' : $path;
        $query = (($query = parse_url($uri, PHP_URL_QUERY)) === null) ? '' : '?' . $query;
        return $path . $query;
    }