- Added some more features to attributes and various Curl wrappers

This commit is contained in:
mcndave committed 2026-07-01 13:24:04 -04:00
1 parent b1adf5a086
commit fe56a1727b
9 files changed
+142 -15

No files matched your search

+9
View File
@@ -18,6 +18,10 @@ class CurlAuthorization
public function fromAuthenticationEnum(AuthenticationEnum $auth,) : static
{
switch($auth) {
case AuthenticationEnum::Custom:
$this->customHeader($this->configuration['header'], $this->configuration['secret']);
break;
case AuthenticationEnum::Bearer:
$this->bearer($this->configuration['token']);
break;
@@ -96,6 +100,11 @@ class CurlAuthorization
$this->userpass(CURLAUTH_NEGOTIATE, $username, $password);
}
public function customHeader(string $header, #[\SensitiveParameter] string $token) : void
{
$this->headers[$header] = $token;
}
public function oauth2(Oauth2GrantTypeEnum $grant, string $oauthTokenUrl, string $redirectUri, string $clientId, string $clientSecret, string $scope) : void
{
$unid = sprintf("oauth_token_%s", md5(serialize($this->configuration)));
+11 -5
View File
@@ -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;