1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 18:13:00 +01:00

Using the correct aggregation strategy when flattening

This change uses the query aggregator associated with the multi-part upload
object to ensure that the correct aggregation strategy is used when flattening
nested POST fields for a multi-part upload. Closes #690.
This commit is contained in:
Michael Dowling 2014-06-04 14:36:17 -07:00
parent 7ad15b806f
commit 3195ebbe24

View File

@ -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);
}