Skip to content

Commit b01d174

Browse files
[BrowserKit][HttpClient][Routing] support building query strings with stringables
1 parent a8e3e66 commit b01d174

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

HttpBrowser.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,18 @@ private function getBodyAndExtraHeaders(Request $request, array $headers): array
9191
return ['', []];
9292
}
9393

94-
return [http_build_query($fields, '', '&', \PHP_QUERY_RFC1738), ['Content-Type' => 'application/x-www-form-urlencoded']];
94+
array_walk_recursive($fields, $caster = static function (&$v) use (&$caster) {
95+
if (\is_object($v)) {
96+
if ($vars = get_object_vars($v)) {
97+
array_walk_recursive($vars, $caster);
98+
$v = $vars;
99+
} elseif (method_exists($v, '__toString')) {
100+
$v = (string) $v;
101+
}
102+
}
103+
});
104+
105+
return [http_build_query($fields, '', '&'), ['Content-Type' => 'application/x-www-form-urlencoded']];
95106
}
96107

97108
protected function getHeaders(Request $request): array

0 commit comments

Comments
 (0)