public static function modifyQuery($uri, array $newQueryParams)
    {
        if ($uri === null) {
            $uri = static::getCurrentRequestUri();
        }

        $query = parse_url($uri, PHP_URL_QUERY);

        $queryParams = [];
        parse_str($query, $queryParams);

        $newQuery = http_build_query(array_merge($queryParams, $newQueryParams));

        $fragment = parse_url($uri, PHP_URL_FRAGMENT);
        return parse_url($uri, PHP_URL_PATH)
        . ($newQuery ? '?' . $newQuery : '')
        . ($fragment ? '#' . $fragment : '');
    }