Documentation

Client
in package
implements HttpClient, HttpAsyncClient

PSR-18 and HTTPlug Async client based on lib-curl.

Tags
license

http://opensource.org/licenses/MIT MIT

author

Михаил Красильников m.krasilnikov@yandex.ru

author

Blake Williams github@shabbyrobe.org

since
1.0

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

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> = []

cURL options .

Tags
throws
NotFoundException

If factory discovery failed.

since
2.0

Accepts PSR-17 factories instead of HTTPlug ones.

__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
throws
InvalidArgumentException

For invalid header names or values.

throws
RuntimeException

If creating the body stream fails.

throws
RequestException

On invalid request.

since
1.6

\UnexpectedValueException replaced with RequestException

since
1.0
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
throws
InvalidArgumentException

For invalid header names or values.

throws
RuntimeException

If creating the body stream fails.

throws
NetworkException

In case of network problems.

throws
RequestException

On invalid request.

since
1.6

\UnexpectedValueException replaced with RequestException

since
1.6

Throw NetworkException on network errors

since
1.0
Return values
ResponseInterface

addRequestBodyOptions()

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>

getProtocolVersion()

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
throws
UnexpectedValueException

If unsupported version requested.

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
throws
InvalidArgumentException

For invalid header names or values.

throws
RuntimeException

If can not read body.

throws
RequestException

On invalid request.

Return values
array<string|int, mixed>

cURL options based on request.


        
On this page

Search results