aboutsummaryrefslogtreecommitdiff
path: root/vendor/guzzlehttp/psr7/src/Query.php
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2024-10-10 16:01:54 +0000
committerAndrew Dolgov <fox@fakecake.org>2024-10-10 16:01:54 +0000
commit468f464b486e2ed0527cfd7e80113d37cdd4d07c (patch)
tree60b3243c3796d6a21a349ee7ae8e5c76d5d2717a /vendor/guzzlehttp/psr7/src/Query.php
parent7fafad2ac2466b9a17b802d9b29d10056b439e29 (diff)
parent124c4e254250ebac336392711b32dfd6fa3caef3 (diff)
Merge branch 'feature/guzzle-7.9.2' into 'master'
Update Guzzle to 7.9.2 See merge request tt-rss/tt-rss!70
Diffstat (limited to 'vendor/guzzlehttp/psr7/src/Query.php')
-rw-r--r--vendor/guzzlehttp/psr7/src/Query.php19
1 files changed, 12 insertions, 7 deletions
diff --git a/vendor/guzzlehttp/psr7/src/Query.php b/vendor/guzzlehttp/psr7/src/Query.php
index 8b9492797..ccf867a0b 100644
--- a/vendor/guzzlehttp/psr7/src/Query.php
+++ b/vendor/guzzlehttp/psr7/src/Query.php
@@ -63,12 +63,15 @@ final class Query
* string. This function does not modify the provided keys when an array is
* encountered (like `http_build_query()` would).
*
- * @param array $params Query string parameters.
- * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
- * to encode using RFC3986, or PHP_QUERY_RFC1738
- * to encode using RFC1738.
+ * @param array $params Query string parameters.
+ * @param int|false $encoding Set to false to not encode,
+ * PHP_QUERY_RFC3986 to encode using
+ * RFC3986, or PHP_QUERY_RFC1738 to
+ * encode using RFC1738.
+ * @param bool $treatBoolsAsInts Set to true to encode as 0/1, and
+ * false as false/true.
*/
- public static function build(array $params, $encoding = PHP_QUERY_RFC3986): string
+ public static function build(array $params, $encoding = PHP_QUERY_RFC3986, bool $treatBoolsAsInts = true): string
{
if (!$params) {
return '';
@@ -86,12 +89,14 @@ final class Query
throw new \InvalidArgumentException('Invalid type');
}
+ $castBool = $treatBoolsAsInts ? static function ($v) { return (int) $v; } : static function ($v) { return $v ? 'true' : 'false'; };
+
$qs = '';
foreach ($params as $k => $v) {
$k = $encoder((string) $k);
if (!is_array($v)) {
$qs .= $k;
- $v = is_bool($v) ? (int) $v : $v;
+ $v = is_bool($v) ? $castBool($v) : $v;
if ($v !== null) {
$qs .= '='.$encoder((string) $v);
}
@@ -99,7 +104,7 @@ final class Query
} else {
foreach ($v as $vv) {
$qs .= $k;
- $vv = is_bool($vv) ? (int) $vv : $vv;
+ $vv = is_bool($vv) ? $castBool($vv) : $vv;
if ($vv !== null) {
$qs .= '='.$encoder((string) $vv);
}