HttpResponsePaginator
in package
implements
Countable, Iterator
Tags
Table of Contents
Interfaces
- Countable
- Iterator
Constants
- SUPPORTED_ENDPOINTS_WITH_CHECKPOINT : array<string|int, string> = ['^\/api\/v2\/logs$', '^\/api\/v2\/organization...
- These endpoints support checkpoint-based pagination (from, take). A 'next' value will be present in responses if more results are available.
Properties
- $httpClient : HttpClient
- $nextCheckpoint : string|null
- The 'next' value pulled from checkpoint-paginated results to indicate next page query id.
- $position : int
- The current position in use by the Iterator, for tracking our index while looping.
- $requestCount : int
- A counter for tracking the number of network requests made for pagination. Does not include any initial network request involved in passing seed data to the class constructor.
- $requestLimit : int
- The 'limit' value returned with the last network response.
- $requestTotal : int
- The 'total' value returned with the last network response.
- $results : array<string|int, array<string|int, mixed>>
- A cache of the paginated results. Appended to when new responses are retrieved from the network.
- $usingCheckpointPagination : bool
- Whether the requested endpoint we're paginated supports checkpoint-based pagination.
Methods
- __construct() : mixed
- HttpResponsePaginator constructor.
- count() : int
- Return the total number of results available, according to the API.
- countNetworkRequests() : int
- Return the total number of network requests made for this paginator instance.
- current() : mixed
- Return the current result at our position, if available.
- key() : int
- Retrieve the current position, if valid.
- next() : void
- Increase our position cursor.
- rewind() : void
- Reset position to 0.
- valid() : bool
- Return true if a result is available. If a result is not immediately available (cached) but the current position is less than the API-reported total results, a paginated network request will be attempted to get the next results. Returns false when no results are available at the current position.
- getNextResults() : bool
- Make a network request for the next page of results.
- lastBuilder() : HttpRequest|null
- Return the current instance of the HttpRequest.
- lastRequest() : RequestInterface|null
- Return a RequestInterface representing the most recent sent HTTP request.
- lastResponse() : ResponseInterface|null
- Return a ResponseInterface representing the most recently returned HTTP response.
- processLastResponse() : bool
- Process the previous HttpResponse results and cache them for iterator content.
- result() : null|array<string|int, mixed>
- Return the current result at our position, if available.
Constants
SUPPORTED_ENDPOINTS_WITH_CHECKPOINT
These endpoints support checkpoint-based pagination (from, take). A 'next' value will be present in responses if more results are available.
private
array<string|int, string>
SUPPORTED_ENDPOINTS_WITH_CHECKPOINT
= ['^\/api\/v2\/logs$', '^\/api\/v2\/organizations$', '^\/api\/v2\/organizations\/(.*)\/members$', '^\/api\/v2\/roles\/(.*)\/users$']
Properties
$httpClient read-only
private
HttpClient
$httpClient
$nextCheckpoint
The 'next' value pulled from checkpoint-paginated results to indicate next page query id.
private
string|null
$nextCheckpoint
= null
$position
The current position in use by the Iterator, for tracking our index while looping.
private
int
$position
= 0
$requestCount
A counter for tracking the number of network requests made for pagination. Does not include any initial network request involved in passing seed data to the class constructor.
private
int
$requestCount
= 0
$requestLimit
The 'limit' value returned with the last network response.
private
int
$requestLimit
= 0
$requestTotal
The 'total' value returned with the last network response.
private
int
$requestTotal
= 0
$results
A cache of the paginated results. Appended to when new responses are retrieved from the network.
private
array<string|int, array<string|int, mixed>>
$results
= []
$usingCheckpointPagination
Whether the requested endpoint we're paginated supports checkpoint-based pagination.
private
bool
$usingCheckpointPagination
= false
Methods
__construct()
HttpResponsePaginator constructor.
public
__construct(HttpClient $httpClient) : mixed
Parameters
- $httpClient : HttpClient
-
an instance of HttpClient to use for paginated network requests
Tags
count()
Return the total number of results available, according to the API.
public
count() : int
Return values
intcountNetworkRequests()
Return the total number of network requests made for this paginator instance.
public
countNetworkRequests() : int
Return values
intcurrent()
Return the current result at our position, if available.
public
current() : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
key()
Retrieve the current position, if valid.
public
key() : int
Return values
intnext()
Increase our position cursor.
public
next() : void
rewind()
Reset position to 0.
public
rewind() : void
valid()
Return true if a result is available. If a result is not immediately available (cached) but the current position is less than the API-reported total results, a paginated network request will be attempted to get the next results. Returns false when no results are available at the current position.
public
valid() : bool
Return values
boolgetNextResults()
Make a network request for the next page of results.
private
getNextResults() : bool
Return values
boollastBuilder()
Return the current instance of the HttpRequest.
private
lastBuilder() : HttpRequest|null
Return values
HttpRequest|nulllastRequest()
Return a RequestInterface representing the most recent sent HTTP request.
private
lastRequest() : RequestInterface|null
Return values
RequestInterface|nulllastResponse()
Return a ResponseInterface representing the most recently returned HTTP response.
private
lastResponse() : ResponseInterface|null
Return values
ResponseInterface|nullprocessLastResponse()
Process the previous HttpResponse results and cache them for iterator content.
private
processLastResponse() : bool
Return values
boolresult()
Return the current result at our position, if available.
private
result() : null|array<string|int, mixed>