Implementata richiesta multipart

This commit is contained in:
Armando Caprio
2021-07-09 10:28:38 +02:00
parent 9f6be70d92
commit 30f7fc050e

View File

@@ -88,6 +88,34 @@ class Guzzle implements Adapter
throw ResponseException::fromRequestException($err);
}
return $response;
}
/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function requestMultiPart(string $method, string $uri, array $data = [], array $headers = []) {
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
}
$multipart = [];
foreach( $data as $key => $value ) {
$multipart[] = [
'name' => $key,
'contents' => $value
];
}
try {
$response = $this->client->$method($uri, [
'headers' => $headers,
'multipart' => $multipart
]);
} catch (RequestException $err) {
throw ResponseException::fromRequestException($err);
}
return $response;
}
}