HttpClient
in package
Class HttpClient.
Table of Contents
- CONTEXT_AUTHENTICATION_CLIENT = 2
- CONTEXT_GENERIC_CLIENT = 1
- CONTEXT_MANAGEMENT_CLIENT = 3
- $basePath : string
- $configuration : SdkConfiguration
- $context : int
- $headers : array<string|int, mixed>
- $lastRequest : HttpRequest|null
- Instance of most recent HttpRequest.
- $mockedResponses : array<string|int, mixed>
- Mocked responses to pass to HttpRequest instances for testing.
- __construct() : mixed
- HttpClient constructor.
- getLastRequest() : HttpRequest|null
- Return a HttpRequest representation of the last built request.
- method() : HttpRequest
- Create a new HttpRequest instance.
- mockResponse() : self
- Inject a series of Psr\Http\Message\ResponseInterface objects into created HttpRequest clients.
- mockResponses() : self
- Inject a series of Psr\Http\Message\ResponseInterface objects into created HttpRequest clients.
Constants
CONTEXT_AUTHENTICATION_CLIENT
public
mixed
CONTEXT_AUTHENTICATION_CLIENT
= 2
CONTEXT_GENERIC_CLIENT
public
mixed
CONTEXT_GENERIC_CLIENT
= 1
CONTEXT_MANAGEMENT_CLIENT
public
mixed
CONTEXT_MANAGEMENT_CLIENT
= 3
Properties
$basePath
private
string
$basePath
= '/'
$configuration
private
SdkConfiguration
$configuration
$context
private
int
$context
= self::CONTEXT_AUTHENTICATION_CLIENT
$headers
private
array<string|int, mixed>
$headers
= []
$lastRequest
Instance of most recent HttpRequest.
private
HttpRequest|null
$lastRequest
= null
$mockedResponses
Mocked responses to pass to HttpRequest instances for testing.
private
array<string|int, mixed>
$mockedResponses
= []
Methods
__construct()
HttpClient constructor.
public
__construct(SdkConfiguration $configuration[, int $context = self::CONTEXT_AUTHENTICATION_CLIENT ][, string $basePath = '/' ][, array<string|int, int|string> $headers = [] ]) : mixed
Parameters
- $configuration : SdkConfiguration
-
Required. Base configuration options for the SDK. See the SdkConfiguration class constructor for options.
- $context : int = self::CONTEXT_AUTHENTICATION_CLIENT
-
Required. The context the client is being created under, either CONTEXT_GENERIC_CLIENT, CONTEXT_AUTHENTICATION_CLIENT, or CONTEXT_MANAGEMENT_CLIENT.
- $basePath : string = '/'
-
Optional. The base URI path from which additional pathing and parameters should be appended.
- $headers : array<string|int, int|string> = []
-
Optional. Additional headers to send with the HTTP request.
Return values
mixed —getLastRequest()
Return a HttpRequest representation of the last built request.
public
getLastRequest() : HttpRequest|null
Return values
HttpRequest|null —method()
Create a new HttpRequest instance.
public
method(string $method) : HttpRequest
Parameters
- $method : string
-
HTTP method to use (GET, POST, PATCH, etc)
Return values
HttpRequest —mockResponse()
Inject a series of Psr\Http\Message\ResponseInterface objects into created HttpRequest clients.
public
mockResponse(ResponseInterface $response[, callable|null $callback = null ][, Exception|null $exception = null ]) : self
Parameters
- $response : ResponseInterface
- $callback : callable|null = null
- $exception : Exception|null = null
Tags
Return values
self —mockResponses()
Inject a series of Psr\Http\Message\ResponseInterface objects into created HttpRequest clients.
public
mockResponses(array<string|int, mixed> $responses) : self
Parameters
- $responses : array<string|int, mixed>