PromiseCore
in package
Shared promises core.
Tags
Table of Contents
Properties
- $exception : Exception|null
- Exception.
- $handle : resource
- cURL handle.
- $onFulfilled : array<string|int, callable>
- Functions to call when a response will be available.
- $onRejected : array<string|int, callable>
- Functions to call when an error happens.
- $request : RequestInterface
- HTTP request.
- $responseBuilder : ResponseBuilder
- Response builder.
- $state : string
- Promise state.
Methods
- __construct() : mixed
- Create shared core.
- addOnFulfilled() : void
- Add on fulfilled callback.
- addOnRejected() : void
- Add on rejected callback.
- fulfill() : void
- Fulfill promise.
- getException() : Throwable
- Get the reason why the promise was rejected.
- getHandle() : resource|CurlHandle
- Return cURL handle.
- getRequest() : RequestInterface
- Return request.
- getResponse() : ResponseInterface
- Return the value of the promise (fulfilled).
- getState() : string
- Get the state of the promise, one of PENDING, FULFILLED or REJECTED.
- reject() : void
- Reject promise.
Properties
$exception
Exception.
private
Exception|null
$exception
= null
$handle
cURL handle.
private
resource
$handle
$onFulfilled
Functions to call when a response will be available.
private
array<string|int, callable>
$onFulfilled
= []
$onRejected
Functions to call when an error happens.
private
array<string|int, callable>
$onRejected
= []
$request
HTTP request.
private
RequestInterface
$request
$responseBuilder
Response builder.
private
ResponseBuilder
$responseBuilder
$state
Promise state.
private
string
$state
Methods
__construct()
Create shared core.
public
__construct(RequestInterface $request, resource|CurlHandle $handle, ResponseBuilder $responseBuilder) : mixed
Parameters
- $request : RequestInterface
-
HTTP request.
- $handle : resource|CurlHandle
-
cURL handle.
- $responseBuilder : ResponseBuilder
-
Response builder.
Tags
addOnFulfilled()
Add on fulfilled callback.
public
addOnFulfilled(callable $callback) : void
Parameters
- $callback : callable
addOnRejected()
Add on rejected callback.
public
addOnRejected(callable $callback) : void
Parameters
- $callback : callable
fulfill()
Fulfill promise.
public
fulfill() : void
getException()
Get the reason why the promise was rejected.
public
getException() : Throwable
If the exception is an instance of Http\Client\Exception\HttpException it will contain the response object with the status code and the http reason.
Tags
Return values
Throwable —Exception Object only when the Promise is rejected
getHandle()
Return cURL handle.
public
getHandle() : resource|CurlHandle
Return values
resource|CurlHandlegetRequest()
Return request.
public
getRequest() : RequestInterface
Return values
RequestInterfacegetResponse()
Return the value of the promise (fulfilled).
public
getResponse() : ResponseInterface
Return values
ResponseInterface —Response object only when the Promise is fulfilled
getState()
Get the state of the promise, one of PENDING, FULFILLED or REJECTED.
public
getState() : string
Return values
stringreject()
Reject promise.
public
reject(Exception $exception) : void
Parameters
- $exception : Exception
-
Reject reason