public static function parse_grip_uri($uri)
    {
        $uri = parse_url($uri);
        $params = array();
        if (array_key_exists('query', $uri)) {
            parse_str($uri['query'], $params);
        }
        $iss = null;
        $key = null;
        if (array_key_exists('iss', $params)) {
            $iss = $params['iss'];
            unset($params['iss']);
        }
        if (array_key_exists('key', $params)) {
            $key = $params['key'];
            unset($params['key']);
        }
        if (!is_null($key) && substr($key, 0, strlen('base64:')) === 'base64:') {
            $key = base64_decode(substr($key, 7));
        }
        $qs = http_build_query($params);
        $path = $uri['path'];
        if (substr($path, strlen($path) - 1) === '/') {
            $path = substr($path, 0, strlen($path) - 1);
        }
        $port = '';
        if (array_key_exists('port', $uri) && $uri['port'] != '' && $uri['port'] != '80') {
            $port = ':' . $uri['port'];
        }
        $control_uri = $uri['scheme'] . '://' . $uri['host'] . $port . $path;
        if (!is_null($qs) && $qs != '') {
            $control_uri .= '?' . $qs;
        }
        $out = array('control_uri' => $control_uri);
        if (!is_null($iss)) {
            $out['control_iss'] = $iss;
        }
        if (!is_null($key)) {
            $out['key'] = $key;
        }
        return $out;
    }