AsyncResponse
in package
implements
ResponseInterface, StreamableInterface
uses
CommonResponseTrait
Provides a single extension point to process a response's content stream.
Tags
Table of Contents
Interfaces
- ResponseInterface
- A (lazily retrieved) HTTP response.
- StreamableInterface
Constants
Properties
- $client : mixed
- $info : mixed
- $passthru : mixed
- $response : mixed
- $stream : mixed
- $yieldedState : mixed
Methods
- __construct() : mixed
- __destruct() : mixed
- cancel() : void
- Closes the response stream and all related buffers.
- getHeaders() : array<string|int, array<string|int, string>>
- Gets the HTTP headers of the response.
- getInfo() : mixed
- Returns info coming from the transport layer.
- getStatusCode() : int
- Gets the HTTP status code of the response.
- toStream() : resource
- Casts the response to a PHP stream resource.
- close() : void
- openBuffer() : Throwable|null
- passthru() : Generator
- passthruStream() : Generator
Constants
FIRST_CHUNK_YIELDED
private
mixed
FIRST_CHUNK_YIELDED
= 1
LAST_CHUNK_YIELDED
private
mixed
LAST_CHUNK_YIELDED
= 2
Properties
$client
private
mixed
$client
$info
private
mixed
$info
= ['canceled' => false]
$passthru
private
mixed
$passthru
$response
private
mixed
$response
$stream
private
mixed
$stream
$yieldedState
private
mixed
$yieldedState
Methods
__construct()
public
__construct(HttpClientInterface $client, string $method, string $url, array<string|int, mixed> $options[, callable(ChunkInterface, AsyncContext): Array|null $passthru = null ]) : mixed
Parameters
- $client : HttpClientInterface
- $method : string
- $url : string
- $options : array<string|int, mixed>
- $passthru : callable(ChunkInterface, AsyncContext): Array|null = null
__destruct()
public
__destruct() : mixed
cancel()
Closes the response stream and all related buffers.
public
cancel() : void
No further chunk will be yielded after this method has been called.
getHeaders()
Gets the HTTP headers of the response.
public
getHeaders([bool $throw = true ]) : array<string|int, array<string|int, string>>
Parameters
- $throw : bool = true
-
Whether an exception should be thrown on 3/4/5xx status codes
Return values
array<string|int, array<string|int, string>> —The headers of the response keyed by header names in lowercase
getInfo()
Returns info coming from the transport layer.
public
getInfo([string|null $type = null ]) : mixed
This method SHOULD NOT throw any ExceptionInterface and SHOULD be non-blocking. The returned info is "live": it can be empty and can change from one call to another, as the request/response progresses.
The following info MUST be returned:
- canceled (bool) - true if the response was canceled using ResponseInterface::cancel(), false otherwise
- error (string|null) - the error message when the transfer was aborted, null otherwise
- http_code (int) - the last response code or 0 when it is not known yet
- http_method (string) - the HTTP verb of the last request
- redirect_count (int) - the number of redirects followed while executing the request
- redirect_url (string|null) - the resolved location of redirect responses, null otherwise
- response_headers (array) - an array modelled after the special $http_response_header variable
- start_time (float) - the time when the request was sent or 0.0 when it's pending
- url (string) - the last effective URL of the request
- user_data (mixed) - the value of the "user_data" request option, null if not set
When the "capture_peer_cert_chain" option is true, the "peer_certificate_chain" attribute SHOULD list the peer certificates as an array of OpenSSL X.509 resources.
Other info SHOULD be named after curl_getinfo()'s associative return value.
Parameters
- $type : string|null = null
Return values
mixed —An array of all available info, or one of them when $type is provided, or null when an unsupported type is requested
getStatusCode()
Gets the HTTP status code of the response.
public
getStatusCode() : int
Return values
inttoStream()
Casts the response to a PHP stream resource.
public
toStream([bool $throw = true ]) : resource
Parameters
- $throw : bool = true
Return values
resourceclose()
private
close() : void
openBuffer()
private
openBuffer() : Throwable|null
Return values
Throwable|nullpassthru()
private
static passthru(HttpClientInterface $client, self $r, ChunkInterface $chunk[, SplObjectStorage<ResponseInterface, AsyncResponse>|null $asyncMap = null ]) : Generator
Parameters
- $client : HttpClientInterface
- $r : self
- $chunk : ChunkInterface
- $asyncMap : SplObjectStorage<ResponseInterface, AsyncResponse>|null = null
Return values
GeneratorpassthruStream()
private
static passthruStream(ResponseInterface $response, self $r, ChunkInterface|null $chunk, SplObjectStorage<ResponseInterface, AsyncResponse>|null $asyncMap) : Generator
Parameters
- $response : ResponseInterface
- $r : self
- $chunk : ChunkInterface|null
- $asyncMap : SplObjectStorage<ResponseInterface, AsyncResponse>|null