Skip to content
Permalink
Browse files

Refactor file processing to make adding PSR7 files easier.

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 7910ce920648e134587c62a729238b6d29c4848b
Showing with 14 additions and 3 deletions.
  1. +14 −3 src/Network/Request.php
@@ -460,17 +460,28 @@ protected static function _base()
*/
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) {
if (isset($data['tmp_name']) && is_string($data['tmp_name'])) {
$post[$key] = $data;
$fileData[$key] = $data;
} else {
$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;
}

0 comments on commit 7910ce9

Please sign in to comment.
You can’t perform that action at this time.