Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/57'
Browse files Browse the repository at this point in the history
Close #57
Fixes #56
  • Loading branch information
weierophinney committed Jun 22, 2015
2 parents 5183448 + fb56a62 commit 320ea38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ All notable changes to this project will be documented in this file, in reverse
- [#51](https://github.com/zendframework/zend-diactoros/pull/51) fixes
`MessageTrait::getHeaderLine()` to return an empty string instead of `null` if
the header is undefined (which is the behavior specified in PSR-7).
- [#57](https://github.com/zendframework/zend-diactoros/pull/57) fixes the
behavior of how the `ServerRequestFactory` marshals upload files when they are
represented as a nested associative array.

## 1.0.3 - 2015-06-04

Expand Down
5 changes: 3 additions & 2 deletions src/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ private static function createUploadedFileFromSpec(array $value)
*/
private static function normalizeNestedFileSpec(array $files = [])
{
$normalizedFiles = [];
foreach (array_keys($files['tmp_name']) as $key) {
$spec = [
'tmp_name' => $files['tmp_name'][$key],
Expand All @@ -477,8 +478,8 @@ private static function normalizeNestedFileSpec(array $files = [])
'name' => $files['name'][$key],
'type' => $files['type'][$key],
];
$files[$key] = self::createUploadedFileFromSpec($spec);
$normalizedFiles[$key] = self::createUploadedFileFromSpec($spec);
}
return $files;
return $normalizedFiles;
}
}
19 changes: 19 additions & 0 deletions test/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,23 @@ public function testNormalizeServerReturnsArrayUnalteredIfApacheHeadersDoNotCont

$this->assertEquals($expected, $server);
}

/**
* @group 57
* @group 56
*/
public function testNormalizeFilesReturnsOnlyActualFilesWhenOriginalFilesContainsNestedAssociativeArrays()
{
$files = [ 'fooFiles' => [
'tmp_name' => ['file' => 'php://temp'],
'size' => ['file' => 0],
'error' => ['file' => 0],
'name' => ['file' => 'foo.bar'],
'type' => ['file' => 'text/plain'],
]];

$normalizedFiles = ServerRequestFactory::normalizeFiles($files);

$this->assertCount(1, $normalizedFiles['fooFiles']);
}
}

0 comments on commit 320ea38

Please sign in to comment.