diff --git a/src/Post/PostBody.php b/src/Post/PostBody.php index 9f80048d..6ba253be 100644 --- a/src/Post/PostBody.php +++ b/src/Post/PostBody.php @@ -245,31 +245,6 @@ class PostBody implements PostBodyInterface return $this->aggregator; } - /** - * Flatten nested fields array into name => value pairs. - * - * @param array $fields Fields to flatten. - * @param string $keyPrefix Key prefix (start with '') - * - * @return array - */ - private static function flattenFields(array $fields, $keyPrefix = '') - { - $result = []; - foreach ($fields as $key => $value) { - if ($keyPrefix) { - $key = "{$keyPrefix}[{$key}]"; - } - if (is_array($value)) { - $result += self::flattenFields($value, $key); - } else { - $result[$key] = $value; - } - } - - return $result; - } - /** * Creates a multipart/form-data body stream * @@ -277,7 +252,13 @@ class PostBody implements PostBodyInterface */ private function createMultipart() { - $fields = self::flattenFields($this->fields); + // Flatten the nested query string values using the correct aggregator + $query = (string) (new Query($this->fields)) + ->setEncodingType(false) + ->setAggregator($this->getAggregator()); + // Convert the flattened query string back into an array + $fields = Query::fromString($query)->toArray(); + return new MultipartBody($fields, $this->files); }