|
@@ -244,6 +244,13 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Whether to merge file uploads as objects (`true`) or arrays (`false`).
|
|
|
|
|
+ *
|
|
|
|
|
+ * @var bool
|
|
|
|
|
+ */
|
|
|
|
|
+ private $mergeFilesAsObjects = false;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Wrapper method to create a new request from PHP superglobals.
|
|
* Wrapper method to create a new request from PHP superglobals.
|
|
|
*
|
|
*
|
|
|
* Uses the $_GET, $_POST, $_FILES, $_COOKIE, $_SERVER, $_ENV and php://input data to construct
|
|
* Uses the $_GET, $_POST, $_FILES, $_COOKIE, $_SERVER, $_ENV and php://input data to construct
|
|
@@ -281,6 +288,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
|
|
|
* - `input` The data that would come from php://input this is useful for simulating
|
|
* - `input` The data that would come from php://input this is useful for simulating
|
|
|
* requests with put, patch or delete data.
|
|
* requests with put, patch or delete data.
|
|
|
* - `session` An instance of a Session object
|
|
* - `session` An instance of a Session object
|
|
|
|
|
+ * - `mergeFilesAsObjects` Whether to merge file uploads as objects (`true`) or arrays (`false`).
|
|
|
*
|
|
*
|
|
|
* @param string|array $config An array of request data to create a request with.
|
|
* @param string|array $config An array of request data to create a request with.
|
|
|
* The string version of this argument is *deprecated* and will be removed in 4.0.0
|
|
* The string version of this argument is *deprecated* and will be removed in 4.0.0
|
|
@@ -302,6 +310,7 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
|
|
|
'base' => '',
|
|
'base' => '',
|
|
|
'webroot' => '',
|
|
'webroot' => '',
|
|
|
'input' => null,
|
|
'input' => null,
|
|
|
|
|
+ 'mergeFilesAsObjects' => false,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$this->_setConfig($config);
|
|
$this->_setConfig($config);
|
|
@@ -364,6 +373,8 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
|
|
|
}
|
|
}
|
|
|
$this->stream = $stream;
|
|
$this->stream = $stream;
|
|
|
|
|
|
|
|
|
|
+ $this->mergeFilesAsObjects = $config['mergeFilesAsObjects'];
|
|
|
|
|
+
|
|
|
$config['post'] = $this->_processPost($config['post']);
|
|
$config['post'] = $this->_processPost($config['post']);
|
|
|
$this->data = $this->_processFiles($config['post'], $config['files']);
|
|
$this->data = $this->_processFiles($config['post'], $config['files']);
|
|
|
$this->query = $this->_processGet($config['query'], $querystr);
|
|
$this->query = $this->_processGet($config['query'], $querystr);
|
|
@@ -436,7 +447,9 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
|
|
|
*/
|
|
*/
|
|
|
protected function _processFiles($post, $files)
|
|
protected function _processFiles($post, $files)
|
|
|
{
|
|
{
|
|
|
- if (!is_array($files)) {
|
|
|
|
|
|
|
+ if (empty($files) ||
|
|
|
|
|
+ !is_array($files)
|
|
|
|
|
+ ) {
|
|
|
return $post;
|
|
return $post;
|
|
|
}
|
|
}
|
|
|
$fileData = [];
|
|
$fileData = [];
|
|
@@ -458,6 +471,10 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
|
|
|
}
|
|
}
|
|
|
$this->uploadedFiles = $fileData;
|
|
$this->uploadedFiles = $fileData;
|
|
|
|
|
|
|
|
|
|
+ if ($this->mergeFilesAsObjects) {
|
|
|
|
|
+ return Hash::merge($post, $fileData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Make a flat map that can be inserted into $post for BC.
|
|
// Make a flat map that can be inserted into $post for BC.
|
|
|
$fileMap = Hash::flatten($fileData);
|
|
$fileMap = Hash::flatten($fileData);
|
|
|
foreach ($fileMap as $key => $file) {
|
|
foreach ($fileMap as $key => $file) {
|