forked from apoloz/alfa-bank-sdk
fix(formating)
This commit is contained in:
@@ -7,6 +7,7 @@ namespace Apoloz\AlfaBank\Core;
|
||||
// <SECTION name="module_imports" intent="Import necessary contracts, services, and base framework components for the connector's operation.">
|
||||
// <BELIEF_STATE "Saloon's plugin architecture requires importing traits for features like retries and timeouts. Local contracts (SignerInterface) are imported for dependency injection.">
|
||||
use Apoloz\AlfaBank\Contracts\SignerInterface;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Apoloz\AlfaBank\Http\Middleware\RequestIdMiddleware;
|
||||
use Apoloz\AlfaBank\Http\Pagination\AlfaOffsetPaginator;
|
||||
use Apoloz\AlfaBank\Traits\HasAlfaErrorHandling;
|
||||
@@ -15,19 +16,18 @@ use Saloon\Http\Connector;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\PaginationPlugin\Contracts\HasPagination;
|
||||
use Saloon\PaginationPlugin\OffsetPaginator;
|
||||
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;
|
||||
use Saloon\Traits\RequestProperties\HasTries;
|
||||
use Saloon\Traits\Plugins\HasTimeout;
|
||||
use Saloon\Traits\OAuth2\AuthorizationCodeGrant;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;
|
||||
use Saloon\Traits\Plugins\HasTimeout;
|
||||
use Saloon\Traits\RequestProperties\HasTries;
|
||||
|
||||
class AlfaBankConnector extends Connector implements HasPagination
|
||||
{
|
||||
use AlwaysThrowOnErrors;
|
||||
use AuthorizationCodeGrant;
|
||||
use HasAlfaErrorHandling;
|
||||
use HasTimeout;
|
||||
use HasTries;
|
||||
use AlwaysThrowOnErrors;
|
||||
use HasAlfaErrorHandling;
|
||||
use AuthorizationCodeGrant;
|
||||
|
||||
public function __construct(
|
||||
protected AlfaConfig $alfaConfig,
|
||||
@@ -42,6 +42,79 @@ class AlfaBankConnector extends Connector implements HasPagination
|
||||
return $this->alfaConfig->baseUrl;
|
||||
}
|
||||
|
||||
public function boot(\Saloon\Http\PendingRequest $pendingRequest): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function paginate(Request $request): OffsetPaginator
|
||||
{
|
||||
return new AlfaOffsetPaginator($this, $request);
|
||||
}
|
||||
|
||||
// login() kept for ClientCredentials compatibility (legacy/simple flow)
|
||||
public function login(?string $clientId = null, ?string $clientSecret = null, array $scopes = []): static
|
||||
{
|
||||
$oauthConfig = $this->oauthConfig();
|
||||
|
||||
// Allow overriding credentials via method arguments
|
||||
if ($clientId) {
|
||||
$oauthConfig->setClientId($clientId);
|
||||
}
|
||||
if ($clientSecret) {
|
||||
$oauthConfig->setClientSecret($clientSecret);
|
||||
}
|
||||
|
||||
if (empty($oauthConfig->getClientId()) || empty($oauthConfig->getClientSecret())) {
|
||||
throw new \RuntimeException('Client ID/Secret not configured.');
|
||||
}
|
||||
|
||||
$request = new \Saloon\Http\OAuth2\GetClientCredentialsTokenRequest($oauthConfig, $scopes);
|
||||
|
||||
$response = $this->send($request);
|
||||
|
||||
// Use the trait's helper to parse the token
|
||||
$authenticator = $this->createOAuthAuthenticatorFromResponse($response);
|
||||
|
||||
$this->authenticate($authenticator);
|
||||
|
||||
return $this;
|
||||
}
|
||||
// </SECTION>
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="signer_accessor" intent="Provide access to the configured signing service for requests that require a digital signature.">
|
||||
// <BELIEF_STATE "Requests should not instantiate their own signing logic. The connector acts as a service locator, providing the globally-configured Signer service. This ensures that all signatures are generated consistently.">
|
||||
public function getSigner(): SignerInterface
|
||||
{
|
||||
if (! $this->signer) {
|
||||
throw new \RuntimeException('No signer configured for this connector.');
|
||||
}
|
||||
|
||||
return $this->signer;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="logging_mutator" intent="Allow attaching a PSR-3 logger to the connector for debugging.">
|
||||
// <BELIEF_STATE "Logging should be an optional, opt-in feature. This method provides a fluent interface to attach a logging middleware, which will automatically sanitize sensitive data before output.">
|
||||
public function withLogging(\Psr\Log\LoggerInterface $logger): static
|
||||
{
|
||||
$this->middleware()->onRequest(new \Apoloz\AlfaBank\Http\Middleware\LoggingRequestMiddleware($logger));
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\LoggingResponseMiddleware($logger));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable automated JWS response verification and decoding.
|
||||
*/
|
||||
public function withJwsVerification(string $publicKeyPem): static
|
||||
{
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\VerifyJwsResponseMiddleware($publicKeyPem));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function defaultOauthConfig(): OAuthConfig
|
||||
{
|
||||
$idUrl = $this->alfaConfig->baseUrl === Environment::PRODUCTION->value
|
||||
@@ -83,80 +156,8 @@ class AlfaBankConnector extends Connector implements HasPagination
|
||||
protected function defaultMiddleware(): array
|
||||
{
|
||||
return [
|
||||
new RequestIdMiddleware(),
|
||||
new RequestIdMiddleware,
|
||||
];
|
||||
}
|
||||
|
||||
public function boot(\Saloon\Http\PendingRequest $pendingRequest): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function paginate(Request $request): OffsetPaginator
|
||||
{
|
||||
return new AlfaOffsetPaginator($this, $request);
|
||||
}
|
||||
|
||||
// login() kept for ClientCredentials compatibility (legacy/simple flow)
|
||||
public function login(?string $clientId = null, ?string $clientSecret = null, array $scopes = []): static
|
||||
{
|
||||
$oauthConfig = $this->oauthConfig();
|
||||
|
||||
// Allow overriding credentials via method arguments
|
||||
if ($clientId) {
|
||||
$oauthConfig->setClientId($clientId);
|
||||
}
|
||||
if ($clientSecret) {
|
||||
$oauthConfig->setClientSecret($clientSecret);
|
||||
}
|
||||
|
||||
if (empty($oauthConfig->getClientId()) || empty($oauthConfig->getClientSecret())) {
|
||||
throw new \RuntimeException("Client ID/Secret not configured.");
|
||||
}
|
||||
|
||||
$request = new \Saloon\Http\OAuth2\GetClientCredentialsTokenRequest($oauthConfig, $scopes);
|
||||
|
||||
$response = $this->send($request);
|
||||
|
||||
// Use the trait's helper to parse the token
|
||||
$authenticator = $this->createOAuthAuthenticatorFromResponse($response);
|
||||
|
||||
$this->authenticate($authenticator);
|
||||
|
||||
return $this;
|
||||
}
|
||||
// </SECTION>
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="signer_accessor" intent="Provide access to the configured signing service for requests that require a digital signature.">
|
||||
// <BELIEF_STATE "Requests should not instantiate their own signing logic. The connector acts as a service locator, providing the globally-configured Signer service. This ensures that all signatures are generated consistently.">
|
||||
public function getSigner(): SignerInterface
|
||||
{
|
||||
if (!$this->signer) {
|
||||
throw new \RuntimeException("No signer configured for this connector.");
|
||||
}
|
||||
return $this->signer;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="logging_mutator" intent="Allow attaching a PSR-3 logger to the connector for debugging.">
|
||||
// <BELIEF_STATE "Logging should be an optional, opt-in feature. This method provides a fluent interface to attach a logging middleware, which will automatically sanitize sensitive data before output.">
|
||||
public function withLogging(\Psr\Log\LoggerInterface $logger): static
|
||||
{
|
||||
$this->middleware()->onRequest(new \Apoloz\AlfaBank\Http\Middleware\LoggingRequestMiddleware($logger));
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\LoggingResponseMiddleware($logger));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable automated JWS response verification and decoding.
|
||||
*/
|
||||
public function withJwsVerification(string $publicKeyPem): static
|
||||
{
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\VerifyJwsResponseMiddleware($publicKeyPem));
|
||||
|
||||
return $this;
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user