Optimise method to set up request params.

parent 32d1fed0
...@@ -166,32 +166,28 @@ class Request ...@@ -166,32 +166,28 @@ class Request
/** /**
* Properly set up the request params * Properly set up the request params
* *
* If any item of the array is a resource, reformat it to a multipart request.
* Else, just return the passed data as form params.
*
* @param array $data * @param array $data
* *
* @return array * @return array
*/ */
private static function setUpRequestParams(array $data) private static function setUpRequestParams(array $data)
{ {
//Check for resources in data $has_resource = false;
$contains_resource = false; $multipart = [];
foreach ($data as $item) {
if (is_resource($item)) {
$contains_resource = true;
break;
}
}
$request_params = []; //Reformat data array in multipart way if it contains a resource
//Reformat data array in multipart way foreach ($data as $key => $item) {
if ($contains_resource) { $has_resource |= is_resource($item);
foreach ($data as $key => $item) { $multipart[] = ['name' => $key, 'contents' => $item];
$request_params['multipart'][] = ['name' => $key, 'contents' => $item]; }
} if ($has_resource) {
} else { return ['multipart' => $multipart];
$request_params['form_params'] = $data;
} }
return $request_params; return ['form_params' => $data];
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment