HttplugClient
in package
implements
ClientInterface, HttpAsyncClient, RequestFactoryInterface, StreamFactoryInterface, UriFactoryInterface, ResetInterface
An adapter to turn a Symfony HttpClientInterface into an Httplug client.
In comparison to Psr18Client, this client supports asynchronous requests.
Run "composer require php-http/discovery php-http/async-client-implementation:*" to get the required dependencies.
Tags
Table of Contents
Interfaces
- ClientInterface
- HttpAsyncClient
- RequestFactoryInterface
- StreamFactoryInterface
- UriFactoryInterface
- ResetInterface
- Provides a way to reset an object to its initial state.
Properties
- $autoUpgradeHttpVersion : bool
- $client : HttpClientInterface
- $promisePool : SplObjectStorage<ResponseInterface, Promise}>|null
- $responseFactory : ResponseFactoryInterface
- $streamFactory : StreamFactoryInterface
- $waitLoop : HttplugWaitLoop
Methods
- __construct() : mixed
- __destruct() : mixed
- __serialize() : array<string|int, mixed>
- __unserialize() : void
- createRequest() : RequestInterface
- Create a new request.
- createStream() : StreamInterface
- Create a new stream from a string.
- createStreamFromFile() : StreamInterface
- Create a stream from an existing file.
- createStreamFromResource() : StreamInterface
- Create a new stream from an existing resource.
- createUri() : UriInterface
- Create a new URI.
- reset() : void
- sendAsyncRequest() : HttplugPromise
- sendRequest() : ResponseInterface
- wait() : int
- Resolves pending promises that complete before the timeouts are reached.
- withOptions() : static
- sendPsr7Request() : ResponseInterface
Properties
$autoUpgradeHttpVersion
private
bool
$autoUpgradeHttpVersion
= true
$client
private
HttpClientInterface
$client
$promisePool
private
SplObjectStorage<ResponseInterface, Promise}>|null
$promisePool
$responseFactory
private
ResponseFactoryInterface
$responseFactory
$streamFactory
private
StreamFactoryInterface
$streamFactory
$waitLoop
private
HttplugWaitLoop
$waitLoop
Methods
__construct()
public
__construct([HttpClientInterface|null $client = null ][, ResponseFactoryInterface|null $responseFactory = null ][, StreamFactoryInterface|null $streamFactory = null ]) : mixed
Parameters
- $client : HttpClientInterface|null = null
- $responseFactory : ResponseFactoryInterface|null = null
- $streamFactory : StreamFactoryInterface|null = null
__destruct()
public
__destruct() : mixed
__serialize()
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__unserialize()
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
createRequest()
Create a new request.
public
createRequest(string $method[, UriInterface|string $uri = '' ]) : RequestInterface
Parameters
- $method : string
-
The HTTP method associated with the request.
- $uri : UriInterface|string = ''
Return values
RequestInterfacecreateStream()
Create a new stream from a string.
public
createStream([string $content = '' ]) : StreamInterface
The stream SHOULD be created with a temporary resource.
Parameters
- $content : string = ''
-
String content with which to populate the stream.
Return values
StreamInterfacecreateStreamFromFile()
Create a stream from an existing file.
public
createStreamFromFile(string $filename[, string $mode = 'r' ]) : StreamInterface
The file MUST be opened using the given mode, which may be any mode
supported by the fopen function.
The $filename MAY be any string supported by fopen().
Parameters
- $filename : string
-
Filename or stream URI to use as basis of stream.
- $mode : string = 'r'
-
Mode with which to open the underlying filename/stream.
Return values
StreamInterfacecreateStreamFromResource()
Create a new stream from an existing resource.
public
createStreamFromResource(mixed $resource) : StreamInterface
The stream MUST be readable and may be writable.
Parameters
- $resource : mixed
-
PHP resource to use as basis of stream.
Return values
StreamInterfacecreateUri()
Create a new URI.
public
createUri([string $uri = '' ]) : UriInterface
Parameters
- $uri : string = ''
Return values
UriInterfacereset()
public
reset() : void
sendAsyncRequest()
public
sendAsyncRequest(RequestInterface $request) : HttplugPromise
Parameters
- $request : RequestInterface
Return values
HttplugPromisesendRequest()
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterfacewait()
Resolves pending promises that complete before the timeouts are reached.
public
wait([float|null $maxDuration = null ][, float|null $idleTimeout = null ]) : int
When $maxDuration is null and $idleTimeout is reached, promises are rejected.
Parameters
- $maxDuration : float|null = null
- $idleTimeout : float|null = null
Return values
int —The number of remaining pending promises
withOptions()
public
withOptions(array<string|int, mixed> $options) : static
Parameters
- $options : array<string|int, mixed>
Return values
staticsendPsr7Request()
private
sendPsr7Request(RequestInterface $request[, bool|null $buffer = null ]) : ResponseInterface
Parameters
- $request : RequestInterface
- $buffer : bool|null = null