Client
in package
implements
HttpClient, HttpAsyncClient
PSR-18 and HTTPlug Async client based on lib-curl.
Tags
Table of Contents
Interfaces
- HttpClient
- HttpAsyncClient
- Sends a PSR-7 Request in an asynchronous way by returning a Promise.
Properties
- $curlOptions : array<string|int, mixed>
- cURL options.
- $handle : resource|CurlHandle|null
- cURL synchronous requests handle.
- $multiRunner : MultiRunner|null
- Simultaneous requests runner.
- $responseFactory : ResponseFactoryInterface
- PSR-17 response factory.
- $streamFactory : StreamFactoryInterface
- PSR-17 stream factory.
Methods
- __construct() : mixed
- Create HTTP client.
- __destruct() : mixed
- Release resources if still active.
- sendAsyncRequest() : Promise
- Sends a PSR-7 request in an asynchronous way.
- sendRequest() : ResponseInterface
- Sends a PSR-7 request and returns a PSR-7 response.
- addRequestBodyOptions() : array<string|int, mixed>
- Add request body related cURL options.
- createHeaders() : array<string|int, string>
- Create headers array for CURLOPT_HTTPHEADER.
- createResponseBuilder() : ResponseBuilder
- Create builder to use for building response object.
- getProtocolVersion() : int
- Return cURL constant for specified HTTP version.
- prepareRequestOptions() : array<string|int, mixed>
- Update cURL options for given request and hook in the response builder.
Properties
$curlOptions
cURL options.
private
array<string|int, mixed>
$curlOptions
$handle
cURL synchronous requests handle.
private
resource|CurlHandle|null
$handle
$multiRunner
Simultaneous requests runner.
private
MultiRunner|null
$multiRunner
$responseFactory
PSR-17 response factory.
private
ResponseFactoryInterface
$responseFactory
$streamFactory
PSR-17 stream factory.
private
StreamFactoryInterface
$streamFactory
Methods
__construct()
Create HTTP client.
public
__construct([ResponseFactoryInterface|null $responseFactory = null ][, StreamFactoryInterface|null $streamFactory = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $responseFactory : ResponseFactoryInterface|null = null
-
PSR-17 HTTP response factory.
- $streamFactory : StreamFactoryInterface|null = null
-
PSR-17 HTTP stream factory.
- $options : array<string|int, mixed> = []
-
Tags
__destruct()
Release resources if still active.
public
__destruct() : mixed
sendAsyncRequest()
Sends a PSR-7 request in an asynchronous way.
public
sendAsyncRequest(RequestInterface $request) : Promise
Exceptions related to processing the request are available from the returned Promise.
Parameters
- $request : RequestInterface
Tags
Return values
Promise —Resolves a PSR-7 Response or fails with an Http\Client\Exception.
sendRequest()
Sends a PSR-7 request and returns a PSR-7 response.
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Tags
Return values
ResponseInterfaceaddRequestBodyOptions()
Add request body related cURL options.
private
addRequestBodyOptions(RequestInterface $request, array<string|int, mixed> $curlOptions) : array<string|int, mixed>
Parameters
- $request : RequestInterface
-
Request on which to create options.
- $curlOptions : array<string|int, mixed>
-
Options created by prepareRequestOptions().
Return values
array<string|int, mixed> —cURL options based on request.
createHeaders()
Create headers array for CURLOPT_HTTPHEADER.
private
createHeaders(RequestInterface $request, array<string|int, mixed> $curlOptions) : array<string|int, string>
Parameters
- $request : RequestInterface
-
Request on which to create headers.
- $curlOptions : array<string|int, mixed>
-
Options created by prepareRequestOptions().
Return values
array<string|int, string>createResponseBuilder()
Create builder to use for building response object.
private
createResponseBuilder() : ResponseBuilder
Return values
ResponseBuildergetProtocolVersion()
Return cURL constant for specified HTTP version.
private
getProtocolVersion(string $requestVersion) : int
Parameters
- $requestVersion : string
-
HTTP version ("1.0", "1.1" or "2.0").
Tags
Return values
int —Respective CURL_HTTP_VERSION_x_x constant.
prepareRequestOptions()
Update cURL options for given request and hook in the response builder.
private
prepareRequestOptions(RequestInterface $request, ResponseBuilder $responseBuilder) : array<string|int, mixed>
Parameters
- $request : RequestInterface
-
Request on which to create options.
- $responseBuilder : ResponseBuilder
-
Builder to use for building response.
Tags
Return values
array<string|int, mixed> —cURL options based on request.