diff --git a/VERSION b/VERSION index c16c0e4..0f7aeca 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2503.200311 +0.2503.200328 diff --git a/src/Http/Content/UrlEncodedFormContent.php b/src/Http/Content/UrlEncodedFormContent.php index be08bae..9ea6c7d 100644 --- a/src/Http/Content/UrlEncodedFormContent.php +++ b/src/Http/Content/UrlEncodedFormContent.php @@ -55,18 +55,6 @@ class UrlEncodedFormContent implements FormContent { ++$this->position; } - /** - * Retrieves all post fields as a query string. - * - * @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder. - * @return string Query string representation of post fields. - */ - public function getParamString(?bool $spacesAsPlus = null): string { - return $spacesAsPlus === null - ? HttpUri::buildQueryString($this->params) - : http_build_query($this->params, '', '&', $spacesAsPlus ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986); - } - /** * Parses URL encoded form params in a stream. * diff --git a/src/Http/HttpParameters.php b/src/Http/HttpParameters.php index 76ed156..378575c 100644 --- a/src/Http/HttpParameters.php +++ b/src/Http/HttpParameters.php @@ -1,7 +1,7 @@ <?php // HttpParameters.php // Created: 2025-03-15 -// Updated: 2025-03-15 +// Updated: 2025-03-20 namespace Index\Http; @@ -84,4 +84,12 @@ interface HttpParameters { array|int $options = 0, mixed $default = null, ): mixed; + + /** + * Retrieves parameters as a query string. + * + * @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder. + * @return string Query string representation of all parameters. + */ + public function getParamString(?bool $spacesAsPlus = null): string; } diff --git a/src/Http/HttpParametersCommon.php b/src/Http/HttpParametersCommon.php index ef23a7f..b324903 100644 --- a/src/Http/HttpParametersCommon.php +++ b/src/Http/HttpParametersCommon.php @@ -1,7 +1,7 @@ <?php // HttpParametersCommon.php // Created: 2025-03-15 -// Updated: 2025-03-15 +// Updated: 2025-03-20 namespace Index\Http; @@ -99,4 +99,26 @@ trait HttpParametersCommon { ? filter_var($this->params[$name][$index], $filter, $options) : $default; } + + /** + * Retrieves parameters as a query string. + * + * @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder. + * @return string Query string representation of all parameters. + */ + public function getParamString(?bool $spacesAsPlus = null): string { + if($spacesAsPlus !== null) { + $params = []; + foreach($this->params as $name => $values) + $params[$name] = match(count($values)) { + 0 => '', + 1 => $values[0], + default => $values, + }; + + return http_build_query($params, '', '&', $spacesAsPlus ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986); + } + + return HttpUri::buildQueryString($this->params); + } } diff --git a/src/Http/HttpRequest.php b/src/Http/HttpRequest.php index 33210db..d6f2591 100644 --- a/src/Http/HttpRequest.php +++ b/src/Http/HttpRequest.php @@ -1,7 +1,7 @@ <?php // HttpRequest.php // Created: 2022-02-08 -// Updated: 2025-03-15 +// Updated: 2025-03-20 namespace Index\Http; @@ -267,18 +267,6 @@ class HttpRequest extends HttpMessage implements ServerRequestInterface, HttpPar return $this->with(params: $query); } - /** - * Retrieves all HTTP request query fields as a query string. - * - * @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder. - * @return string Query string representation of query fields. - */ - public function getParamString(?bool $spacesAsPlus = null): string { - return $spacesAsPlus === null - ? HttpUri::buildQueryString($this->params) - : http_build_query($this->params, '', '&', $spacesAsPlus ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986); - } - /** * @return array<string, UploadedFileInterface[]> An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present. */