Files
alfa-bank-sdk/src/Requests/Auth/UserInfo/GetClientConsentsRequest.php

71 lines
3.6 KiB
PHP

<?php
/*
// MODULE_CONTRACT: Represents the API call to retrieve a list of client consents for user information access.
// RESPONSIBILITY: To define the GET request for fetching consent details, with various filtering and pagination options.
// INPUTS: Optional client ID, subject ID, organization hash, active status, and pagination parameters.
// OUTPUTS: ClientConsentCollectionData (DTO).
*/
namespace Apoloz\AlfaBank\Requests\Auth\UserInfo;
// <SECTION name="module_imports" intent="Import DTO and Saloon framework components.">
// <BELIEF_STATE "This request requires the `ClientConsentCollectionData` DTO for its response, as it returns a paginated list of consents.">
use Apoloz\AlfaBank\Data\Auth\UserInfo\ClientConsentCollectionData;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
// </SECTION>
// <SECTION name="class_definition" intent="Define a class for retrieving client consents.">
// <BELIEF_STATE "Encapsulating the consent retrieval logic in a dedicated class provides a clear, reusable interface for auditing and managing user consents.">
class GetClientConsentsRequest extends Request
{
// <SECTION name="http_method_declaration" intent="Declare the HTTP verb for fetching consents.">
// <BELIEF_STATE "Retrieving consent information is a read-only operation, thus GET is the appropriate RESTful method.">
protected Method $method = Method::GET;
// </SECTION>
// <SECTION name="constructor" intent="Inject all possible filter and pagination parameters.">
// <BELIEF_STATE "The constructor supports a wide array of optional filters (e.g., `clientId`, `sub`, `organizationIdHash`, `isActive`) and pagination (`limit`, `offset`), allowing for granular control over the retrieved consent list.">
public function __construct(
protected ?string $clientId = null,
protected ?string $sub = null,
protected ?string $organizationIdHash = null,
protected ?bool $isActive = null,
protected ?int $limit = 1000,
protected ?int $offset = 0,
) {}
// </SECTION>
// <SECTION name="endpoint_resolver" intent="Define the specific URI for the client consents endpoint.">
// <BELIEF_STATE "The `/oidc/client-consents` endpoint is the standard path for accessing consent information within the OIDC framework.">
public function resolveEndpoint(): string
{
return '/oidc/client-consents';
}
// </SECTION>
// <SECTION name="query_parameter_builder" intent="Construct the query string for filtering and pagination.">
// <BELIEF_STATE "The `array_filter` function is used to dynamically build the query parameters, ensuring that only non-null values are included in the request, which results in clean and efficient API calls.">
protected function defaultQuery(): array
{
return array_filter([
'clientId' => $this->clientId,
'sub' => $this->sub,
'organizationIdHash' => $this->organizationIdHash,
'isActive' => $this->isActive,
'limit' => $this->limit,
'offset' => $this->offset,
], fn($value) => $value !== null);
}
// </SECTION>
// <SECTION name="response_dto_caster" intent="Transform the raw JSON response into a structured ClientConsentCollectionData DTO.">
// <BELIEF_STATE "Automatically casting the JSON response to a `ClientConsentCollectionData` DTO provides type safety and a clean, object-oriented way to access the list of consents and any associated metadata.">
public function createDtoFromResponse(Response $response): ClientConsentCollectionData
{
return ClientConsentCollectionData::from($response->json());
}
// </SECTION>
}