- Added some more features to attributes and various Curl wrappers
This commit is contained in:
1 parent
b1adf5a086
commit
fe56a1727b
9 files changed
+142
-15
No files matched your search
@@ -6,7 +6,7 @@ use Ulmus\Api\Common\{ ContentTypeEnum, MethodEnum, HttpHeaderEnum };
|
||||
use Ulmus\Api\Stream\JsonStream;
|
||||
use Ulmus\Api\Stream\Stream;
|
||||
use Psr\Http\Message\{RequestInterface, ResponseInterface, StreamInterface};
|
||||
use Ulmus\Api\Response\{ Response, JsonResponse };
|
||||
use Ulmus\Api\Response\{Response, JsonResponse, XmlResponse};
|
||||
|
||||
abstract class CurlTransport {
|
||||
|
||||
@@ -37,9 +37,9 @@ abstract class CurlTransport {
|
||||
return $this->request(MethodEnum::Post, $url, $data, $headers, $curlOptions);
|
||||
}
|
||||
|
||||
public function get(string $url, mixed $data, array $headers = [], array $curlOptions = []) : mixed
|
||||
public function get(string $url, array $headers = [], array $curlOptions = []) : mixed
|
||||
{
|
||||
return $this->request(MethodEnum::Get, $url, $data, $headers, $curlOptions);
|
||||
return $this->request(MethodEnum::Get, $url, null, $headers, $curlOptions);
|
||||
}
|
||||
|
||||
public function delete(string $url, mixed $data, array $headers = [], array $curlOptions = []) : mixed
|
||||
@@ -130,8 +130,14 @@ abstract class CurlTransport {
|
||||
|
||||
$response = $response->withBody( Stream::fromMemory($result) );
|
||||
|
||||
if ( $response->hasHeader('Content-Type') && false !== strpos($response->getHeader('Content-Type')[0], 'json') ) {
|
||||
$response = JsonResponse::fromResponse($response);
|
||||
if ($response->hasHeader('Content-Type') ) {
|
||||
list($mime) = explode(';', $response->getHeader('Content-Type')[0]);
|
||||
|
||||
return match(ContentTypeEnum::tryFrom($mime)) {
|
||||
ContentTypeEnum::Json => JsonResponse::fromResponse($response),
|
||||
ContentTypeEnum::RssXml, ContentTypeEnum::Xml => XmlResponse::fromResponse($response),
|
||||
default => $response,
|
||||
};
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
Reference in new issue
Block a user