ClientAdapterInterface
in
Interface for HTTP client adapters
Table of Contents
- concurrent() : array<string|int, mixed>
- Backs bulk async billig call, running multiple concurrent requests at once.
- send() : ResponseInterface
- Methd to perform HTTP call
- sendAsync() : mixed
- Performs Client-specific async request and return promise
Methods
concurrent()
Backs bulk async billig call, running multiple concurrent requests at once.
public
concurrent(iteratable<string|int, mixed> $requests[, int $concurency = 20 ]) : array<string|int, mixed>
Takes array/iterable of requests and returns array of results, either good (ResponceInterface object) or bad (PortaException exception)
Array keys must be preserved!
The adaptor must return Response objects with non-200 HTTP return codes instead of excepton of HTTP errors
Parameters
- $requests : iteratable<string|int, mixed>
-
keyed iterable of requests to render in parallel
- $concurency : int = 20
-
how much calls to run in parallel. Default is 20.
Return values
array<string|int, mixed> —send()
Methd to perform HTTP call
public
send(RequestInterface $request) : ResponseInterface
This method should accept request, complete the call and return response.
Any client-specific exceptions must be catched and converted to PortaConnectException to throw.
The client must return Response objects with non-200 HTTP return codes instead of throw an error.
Parameters
- $request : RequestInterface
Tags
Return values
ResponseInterface —sendAsync()
Performs Client-specific async request and return promise
public
sendAsync(RequestInterface $request) : mixed
As promise have no standard yet, rely in most adopted Promise/A which seems to be about the same for the most popular implementation like React and Guzzle, so future processing rely on presence of then() method regardles of implementation.
Future processing rely on promise:
- Fulfilled with ResponseInterface, got from billing sserver on success
- Rejected with one of PortaException childs on fail Also, the adapter class have to wrap the promise it got form client to another promise which will rework client-dependent exceptions into PortaException class exceptions.
The promise must fulfil Response objects with non-200 HTTP return codes instead of reject with exceptions on HTTP errors. Some clients may return custom exceptions on HTTP erors, containing request object, so this excepton must be reworked to promise fulfill with Respose object.
Parameters
- $request : RequestInterface
-
request to send in async mode
Return values
mixed —Client-dependent promise object.
It must fulfill with ResponseInterface or reject with PortaException or it's child.