Skip to content

Commit

Permalink
Refactor file processing to make adding PSR7 files easier.
Browse files Browse the repository at this point in the history
Update the code so it will be easier to inject UploadedFile objects into
the request.
  • Loading branch information
markstory committed Sep 4, 2016
1 parent 8932977 commit 7910ce9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Network/Request.php
Expand Up @@ -460,17 +460,28 @@ protected static function _base()
*/ */
protected function _processFiles($post, $files) protected function _processFiles($post, $files)
{ {
if (is_array($files)) { if (!is_array($files)) {
return $post;
}

$fileData = [];
foreach ($files as $key => $data) {
foreach ($files as $key => $data) { foreach ($files as $key => $data) {
if (isset($data['tmp_name']) && is_string($data['tmp_name'])) { if (isset($data['tmp_name']) && is_string($data['tmp_name'])) {
$post[$key] = $data; $fileData[$key] = $data;
} else { } else {
$keyData = isset($post[$key]) ? $post[$key] : []; $keyData = isset($post[$key]) ? $post[$key] : [];
$post[$key] = $this->_processFileData($keyData, $data); $fileData[$key] = $this->_processFileData($keyData, $data);
} }
} }
} }


// Make a flat map that can be inserted into $post for BC.
$fileMap = Hash::flatten($fileData);
foreach ($fileMap as $key => $file) {
$post = Hash::insert($post, $key, $file);
}

return $post; return $post;
} }


Expand Down

0 comments on commit 7910ce9

Please sign in to comment.