11<?php
2+
23/**
34 * ObjectSerializer
45 *
5- * PHP version 7.4
6+ * PHP version 7.4+
67 *
78 * @category Class
89 * @package { {invokerPackage} }
@@ -182,12 +183,16 @@ class ObjectSerializer
182183 case ' float' :
183184 return $value !== 0 && $value !== 0.0;
184185
185- # For boolean values, ' ' is considered empty
186+ # For boolean values, ' ' is considered empty
186187 case ' bool' :
187188 case ' boolean' :
188189 return !in_array($value, [false, 0], true);
189190
190- # For all the other types, any value at this point can be considered empty.
191+ # For string values, ' ' is considered empty.
192+ case ' string' :
193+ return $value === ' ' ;
194+
195+ # For all the other types, any value at this point can be considered empty.
191196 default:
192197 return true;
193198 }
@@ -242,6 +247,7 @@ class ObjectSerializer
242247 return $arr;
243248 }
244249
250+
245251 foreach ($arr as $k => $v) {
246252 $prop = ($style === ' deepObject' ) ? $prop = "{$name}[{$k}]" : $k;
247253
@@ -260,6 +266,11 @@ class ObjectSerializer
260266
261267 $value = $flattenArray($value, $paramName);
262268
269+ // https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values
270+ if ($openApiType === ' array' && $style === ' deepObject' && $explode) {
271+ return $value;
272+ }
273+
263274 if ($openApiType === ' object' && ($style === ' deepObject' || $explode)) {
264275 return $value;
265276 }
@@ -283,7 +294,7 @@ class ObjectSerializer
283294 */
284295 public static function convertBoolToQueryStringFormat(bool $value)
285296 {
286- if (Configuration::BOOLEAN_FORMAT_STRING == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) {
297+ if (Configuration::BOOLEAN_FORMAT_STRING === Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()) {
287298 return $value ? ' true ' : ' false ' ;
288299 }
289300
@@ -333,7 +344,7 @@ class ObjectSerializer
333344 * If it' s a datetime object, format it in ISO8601
334345 * If it' s a boolean, convert it to " true" or " false" .
335346 *
336- * @param string |bool|\DateTime $value the value of the parameter
347+ * @param float|int |bool|\DateTime $value the value of the parameter
337348 *
338349 * @return string the header string
339350 */
@@ -391,7 +402,6 @@ class ObjectSerializer
391402 * @param mixed $data object or primitive to be deserialized
392403 * @param string $class class name is passed as a string
393404 * @param string[] $httpHeaders HTTP headers
394- * @param string $discriminator discriminator if polymorphism is used
395405 *
396406 * @return object|array|null a single or an array of $class instances
397407 */
@@ -541,22 +551,64 @@ class ObjectSerializer
541551 }
542552
543553 /**
544- * Native `http_build_query` wrapper.
545- * @see https://www.php.net/manual/en/function.http-build-query
546- *
547- * @param array|object $data May be an array or object containing properties.
548- * @param string $numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only.
549- * @param string|null $arg_separator arg_separator.output is used to separate arguments but may be overridden by specifying this parameter.
550- * @param int $encoding_type Encoding type. By default, PHP_QUERY_RFC1738.
551- *
552- * @return string
553- */
554- public static function buildQuery(
555- $data,
556- string $numeric_prefix = '',
557- ?string $arg_separator = null,
558- int $encoding_type = \PHP_QUERY_RFC3986
559- ): string {
560- return \GuzzleHttp\Psr7\Query::build($data , $encoding_type );
554+ * Build a query string from an array of key value pairs.
555+ *
556+ * This function can use the return value of `parse()` to build a query
557+ * string. This function does not modify the provided keys when an array is
558+ * encountered (like `http_build_query()` would).
559+ *
560+ * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112
561+ * with a modification which is described in https://github.com/guzzle/psr7/pull/603
562+ *
563+ * @param array $params Query string parameters.
564+ * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
565+ * to encode using RFC3986, or PHP_QUERY_RFC1738
566+ * to encode using RFC1738.
567+ */
568+ public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
569+ {
570+ if (! $params ) {
571+ return ' ' ;
572+ }
573+
574+ if ($encoding === false) {
575+ $encoder = function (string $str ): string {
576+ return $str ;
577+ } ;
578+ } elseif ($encoding === PHP_QUERY_RFC3986) {
579+ $encoder = ' rawurlencode' ;
580+ } elseif ($encoding === PHP_QUERY_RFC1738) {
581+ $encoder = ' urlencode' ;
582+ } else {
583+ throw new \InvalidArgumentException(' Invalid type' );
584+ }
585+
586+ $castBool = Configuration::BOOLEAN_FORMAT_INT === Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString()
587+ ? function ($v) { return (int) $v ; }
588+ : function ($v) { return $v ? ' true' : ' false' ; } ;
589+
590+ $qs = '';
591+ foreach ($params as $k => $v) {
592+ $k = $encoder ((string) $k );
593+ if (! is_array($v )) {
594+ $qs .= $k ;
595+ $v = is_bool($v ) ? $castBool ($v ) : $v ;
596+ if ($v !== null) {
597+ $qs .= ' =' .$encoder ((string) $v );
598+ }
599+ $qs .= '& ';
600+ } else {
601+ foreach ($v as $vv ) {
602+ $qs .= $k ;
603+ $vv = is_bool($vv ) ? $castBool ($vv ) : $vv ;
604+ if ($vv !== null) {
605+ $qs .= ' =' .$encoder ((string) $vv );
606+ }
607+ $qs .= '& ';
608+ }
609+ }
610+ }
611+
612+ return $qs ? (string) substr($qs, 0, -1) : '';
561613 }
562614}
0 commit comments