protected static function parseQuery($query)
    {
        if (is_array($query))
            return $query;

        if (empty($query))
            return null;

        if (!is_string($query))
            throw new \InvalidArgumentException('Query must be associative array or string');
        
        $query = ltrim($query, '?');
        $query = str_replace('&amp;', '&', $query);
        $parts = explode('&', $query);
        $values = [];
        foreach ($parts as $part)
        {
            $subparts = explode('=', $part, 2);
            if (count($subparts) === 1)
                $values[$part] = '1';
            else
                $values[$subparts[0]] = $subparts[1];
        }

        return empty($values) ? null : $values;
    }