Skip to content

Commit d250db3

Browse files
committed
minor #43612 [BrowserKit][HttpClient][Routing] support building query strings with stringables (nicolas-grekas, OskarStark)
This PR was merged into the 5.4 branch. Discussion ---------- [BrowserKit][HttpClient][Routing] support building query strings with stringables | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes (minor) | Deprecations? | no | Tickets | Fix #26992 | License | MIT | Doc PR | - Allows using eg an instance of `Uid` as a route parameter. Replaces #42057 Commits ------- 65e2caca30 Add check and tests for public properties ab38bb8b6c [BrowserKit][HttpClient][Routing] support building query strings with stringables
2 parents 5392db9 + b01d174 commit d250db3

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)