public static function parseRequestParams(string $source) : array
{
// '[' is urlencoded in the input, but we must urldecode it in order
// to find it when replacing names with the regexp below.
$source = str_replace(urlencode('['), '[', $source);
$source = preg_replace_callback('/(^|(?<=&))[^=[&]+/', function ($key) {
return bin2hex(urldecode($key[0]));
}, $source);
// parse_str urldecodes both keys and values in resulting array.
parse_str($source, $params);
return array_combine(array_map('hex2bin', array_keys($params)), $params);
}