HttpClient
in package
Table of Contents
Constants
- RETRY_STATUS_CODES : mixed = [429, 500, 502, 503, 504]
Properties
- $apiKey : string
- $baseUrl : string
- $client : Client
- $clientId : string|null
- $maxRetries : int
- $timeout : int
- $userAgent : string|null
Methods
- __construct() : mixed
- buildUrl() : string
- Build a fully-qualified URL without making an HTTP request.
- getApiKey() : string|null
- getClientId() : string|null
- request() : array<string|int, mixed>|null
- requestPage() : PaginatedResponse
- requireApiKey() : string
- requireClientId() : string
- buildRequestOptions() : array<string|int, mixed>
-
decodeErrorBody()
: array{message: string, code: ?string, error: ?string, rawBody: ?array
} - Parse an error response body into the fields used to build an {@see ApiException}.
- decodeResponse() : array<string|int, mixed>|null
- encodePathSegment() : string
- encodePathSegments() : string
- RFC 3986 path-segment encoding for an entire path string.
- isTimeoutException() : bool
- mapApiException() : ApiException
- Map a 4xx/5xx HTTP response to the corresponding {@see ApiException} subclass.
- mapTransportException() : Exception
- parseRetryAfter() : int|null
- resolveMaxRetries() : int
- resolveTimeout() : int
- resolveUrl() : string
- sleep() : void
Constants
RETRY_STATUS_CODES
private
mixed
RETRY_STATUS_CODES
= [429, 500, 502, 503, 504]
Properties
$apiKey read-only
private
string
$apiKey
$baseUrl read-only
private
string
$baseUrl
$client
private
Client
$client
$clientId read-only
private
string|null
$clientId
$maxRetries read-only
private
int
$maxRetries
$timeout read-only
private
int
$timeout
$userAgent read-only
private
string|null
$userAgent
= null
Methods
__construct()
public
__construct(string $apiKey, string|null $clientId, string $baseUrl, int $timeout, int $maxRetries[, HandlerStack|null $handler = null ][, string|null $userAgent = null ]) : mixed
Parameters
- $apiKey : string
- $clientId : string|null
- $baseUrl : string
- $timeout : int
- $maxRetries : int
- $handler : HandlerStack|null = null
- $userAgent : string|null = null
buildUrl()
Build a fully-qualified URL without making an HTTP request.
public
buildUrl(string $path[, array<string, mixed> $query = [] ][, RequestOptions|null $options = null ]) : string
Used for redirect endpoints (e.g., SSO authorize, logout) where the caller needs a URL to redirect the user's browser to.
Parameters
- $path : string
- $query : array<string, mixed> = []
- $options : RequestOptions|null = null
Return values
stringgetApiKey()
public
getApiKey() : string|null
Return values
string|nullgetClientId()
public
getClientId() : string|null
Return values
string|nullrequest()
public
request(string $method, string $path[, array<string|int, mixed>|null $query = null ][, array<string|int, mixed>|null $body = null ][, RequestOptions|null $options = null ]) : array<string|int, mixed>|null
Parameters
- $method : string
- $path : string
- $query : array<string|int, mixed>|null = null
- $body : array<string|int, mixed>|null = null
- $options : RequestOptions|null = null
Return values
array<string|int, mixed>|nullrequestPage()
public
requestPage(string $method, string $path[, array<string|int, mixed>|null $query = null ][, array<string|int, mixed>|null $body = null ][, string|null $modelClass = null ][, RequestOptions|null $options = null ]) : PaginatedResponse
Parameters
- $method : string
- $path : string
- $query : array<string|int, mixed>|null = null
- $body : array<string|int, mixed>|null = null
- $modelClass : string|null = null
- $options : RequestOptions|null = null
Return values
PaginatedResponserequireApiKey()
public
requireApiKey() : string
Return values
stringrequireClientId()
public
requireClientId() : string
Return values
stringbuildRequestOptions()
private
buildRequestOptions(string $method, array<string|int, mixed>|null $query, array<string|int, mixed>|null $body, RequestOptions|null $options) : array<string|int, mixed>
Parameters
- $method : string
- $query : array<string|int, mixed>|null
- $body : array<string|int, mixed>|null
- $options : RequestOptions|null
Return values
array<string|int, mixed>decodeErrorBody()
Parse an error response body into the fields used to build an {@see ApiException}.
private
decodeErrorBody(ResponseInterface $response) : array{message: string, code: ?string, error: ?string, rawBody: ?array}
Falls back to a synthetic message when the body is empty, and treats the
raw contents as the message when the body isn't valid JSON. The decoded
body itself (when JSON-shaped) is always returned in rawBody for callers
that need to read additional response fields.
Parameters
- $response : ResponseInterface
Return values
array{message: string, code: ?string, error: ?string, rawBody: ?arraydecodeResponse()
private
decodeResponse(ResponseInterface $response) : array<string|int, mixed>|null
Parameters
- $response : ResponseInterface
Return values
array<string|int, mixed>|nullencodePathSegment()
private
static encodePathSegment(string $segment) : string
Parameters
- $segment : string
Return values
stringencodePathSegments()
RFC 3986 path-segment encoding for an entire path string.
private
static encodePathSegments(string $path) : string
Splits $path on /, percent-encodes any unsafe characters in each
segment, and reassembles with / separators. Existing valid
percent-encoded triplets (%XX) are preserved verbatim, so generated
services that already call rawurlencode($id) are not double-encoded.
Defense-in-depth: when a service forgets to encode an interpolated ID
like om_xyz?foo, non-slash unsafe characters (?, #, etc.) inside
the segment are percent-encoded instead of opening a new query or
fragment. A raw / inside an unencoded ID still acts as a path
separator — callers are responsible for rawurlencode-ing IDs that can
contain /.
Parameters
- $path : string
Return values
stringisTimeoutException()
private
isTimeoutException(Throwable $exception) : bool
Parameters
- $exception : Throwable
Return values
boolmapApiException()
Map a 4xx/5xx HTTP response to the corresponding {@see ApiException} subclass.
private
mapApiException(ResponseInterface $response[, Throwable|null $previous = null ]) : ApiException
The full decoded JSON body (if any) is threaded through to the exception's
$rawBody property so callers can read fields the SDK doesn't surface as
dedicated properties (e.g. pending_authentication_token from headless AuthKit).
Parameters
- $response : ResponseInterface
-
The error response.
- $previous : Throwable|null = null
-
Underlying transport exception, if any.
Return values
ApiExceptionmapTransportException()
private
mapTransportException(Throwable $exception) : Exception
Parameters
- $exception : Throwable
Return values
ExceptionparseRetryAfter()
private
parseRetryAfter(string|null $retryAfter) : int|null
Parameters
- $retryAfter : string|null
Return values
int|nullresolveMaxRetries()
private
resolveMaxRetries(RequestOptions|null $options) : int
Parameters
- $options : RequestOptions|null
Return values
intresolveTimeout()
private
resolveTimeout(RequestOptions|null $options) : int
Parameters
- $options : RequestOptions|null
Return values
intresolveUrl()
private
resolveUrl(string $path, RequestOptions|null $options) : string
Parameters
- $path : string
- $options : RequestOptions|null
Return values
stringsleep()
private
sleep(int $attempt[, string|null $retryAfter = null ]) : void
Parameters
- $attempt : int
- $retryAfter : string|null = null