PaginatedResponse
in package
PaginatedResponse Class
Wrapper class for HTTP responses that provides pagination functionality. This class encapsulates an HTTP response and provides methods to navigate through paginated results using Canvas API Link headers.
Usage:
$response = $httpClient->get('/api/v1/courses');
$paginatedResponse = new PaginatedResponse($response, $httpClient);
$result = $paginatedResponse->toPaginationResult($courses);
if ($paginatedResponse->hasNext()) {
$nextResponse = $paginatedResponse->getNext();
}
Table of Contents
Properties
- $httpClient : HttpClientInterface
- HTTP client for making additional requests
- $linkHeader : string|null
- Cached Link header string
- $linkParser : LinkHeaderParser
- Link header parser instance
- $navigationUrls : array<string|int, string>
- Parsed Link header navigation URLs
- $response : ResponseInterface
- The HTTP response
Methods
- __construct() : mixed
- PaginatedResponse constructor
- fetchAllPages() : array<string|int, mixed>
- Fetch all pages starting from current page
- getBody() : string
- Get the response body as string
- getCurrentPage() : int
- Get the current page number
- getCurrentUrl() : string|null
- Get the current page URL
- getFirst() : self|null
- Fetch the first page
- getFirstUrl() : string|null
- Get the first page URL
- getJsonData() : array<string|int, mixed>
- Get the response body as decoded JSON array
- getLast() : self|null
- Fetch the last page
- getLastUrl() : string|null
- Get the last page URL
- getLinkHeader() : string
- Get the Link header from the response
- getNavigationUrls() : array<string|int, string>
- Get all navigation URLs
- getNext() : self|null
- Fetch the next page
- getNextUrl() : string|null
- Get the next page URL
- getPaginationInfo() : array<string|int, mixed>
- Get pagination summary information
- getPerPage() : int|null
- Get the per_page parameter
- getPrev() : self|null
- Fetch the previous page
- getPrevUrl() : string|null
- Get the previous page URL
- getResponse() : ResponseInterface
- Get the underlying HTTP response
- getTotalPages() : int|null
- Get the total number of pages
- getUrl() : string|null
- Get URL for specific relation
- hasNext() : bool
- Check if there is a next page
- hasPrev() : bool
- Check if there is a previous page
- hasRelation() : bool
- Check if relation exists in Link header
- toPaginationResult() : PaginationResult
- Convert to PaginationResult
- fetchUrl() : self|null
- Fetch a specific page by URL
- parseLinkHeader() : array<string|int, string>
- Parse Link header and extract navigation URLs
Properties
$httpClient
HTTP client for making additional requests
private
HttpClientInterface
$httpClient
$linkHeader
Cached Link header string
private
string|null
$linkHeader
= null
$linkParser
Link header parser instance
private
LinkHeaderParser
$linkParser
$navigationUrls
Parsed Link header navigation URLs
private
array<string|int, string>
$navigationUrls
$response
The HTTP response
private
ResponseInterface
$response
Methods
__construct()
PaginatedResponse constructor
public
__construct(ResponseInterface $response, HttpClientInterface $httpClient) : mixed
Parameters
- $response : ResponseInterface
-
The HTTP response
- $httpClient : HttpClientInterface
-
HTTP client for additional requests
fetchAllPages()
Fetch all pages starting from current page
public
fetchAllPages() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array containing all data from all pages
getBody()
Get the response body as string
public
getBody() : string
Return values
stringgetCurrentPage()
Get the current page number
public
getCurrentPage() : int
Return values
intgetCurrentUrl()
Get the current page URL
public
getCurrentUrl() : string|null
Return values
string|nullgetFirst()
Fetch the first page
public
getFirst() : self|null
Return values
self|nullgetFirstUrl()
Get the first page URL
public
getFirstUrl() : string|null
Return values
string|nullgetJsonData()
Get the response body as decoded JSON array
public
getJsonData() : array<string|int, mixed>
Return values
array<string|int, mixed>getLast()
Fetch the last page
public
getLast() : self|null
Return values
self|nullgetLastUrl()
Get the last page URL
public
getLastUrl() : string|null
Return values
string|nullgetLinkHeader()
Get the Link header from the response
public
getLinkHeader() : string
Return values
stringgetNavigationUrls()
Get all navigation URLs
public
getNavigationUrls() : array<string|int, string>
Return values
array<string|int, string>getNext()
Fetch the next page
public
getNext() : self|null
Return values
self|nullgetNextUrl()
Get the next page URL
public
getNextUrl() : string|null
Return values
string|nullgetPaginationInfo()
Get pagination summary information
public
getPaginationInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>getPerPage()
Get the per_page parameter
public
getPerPage() : int|null
Return values
int|nullgetPrev()
Fetch the previous page
public
getPrev() : self|null
Return values
self|nullgetPrevUrl()
Get the previous page URL
public
getPrevUrl() : string|null
Return values
string|nullgetResponse()
Get the underlying HTTP response
public
getResponse() : ResponseInterface
Return values
ResponseInterfacegetTotalPages()
Get the total number of pages
public
getTotalPages() : int|null
Return values
int|nullgetUrl()
Get URL for specific relation
public
getUrl(string $relation) : string|null
Parameters
- $relation : string
-
The relation (next, prev, first, last, current)
Return values
string|nullhasNext()
Check if there is a next page
public
hasNext() : bool
Return values
boolhasPrev()
Check if there is a previous page
public
hasPrev() : bool
Return values
boolhasRelation()
Check if relation exists in Link header
public
hasRelation(string $relation) : bool
Parameters
- $relation : string
-
The relation to check
Return values
booltoPaginationResult()
Convert to PaginationResult
public
toPaginationResult(array<string|int, mixed> $data) : PaginationResult
Parameters
- $data : array<string|int, mixed>
-
The decoded response data
Return values
PaginationResultfetchUrl()
Fetch a specific page by URL
private
fetchUrl(string $url) : self|null
Parameters
- $url : string
-
The URL to fetch
Return values
self|nullparseLinkHeader()
Parse Link header and extract navigation URLs
private
parseLinkHeader() : array<string|int, string>