Documentation

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

$linkHeader

Cached Link header string

private string|null $linkHeader = null

$navigationUrls

Parsed Link header navigation URLs

private array<string|int, string> $navigationUrls

Methods

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
string

getCurrentPage()

Get the current page number

public getCurrentPage() : int
Return values
int

getCurrentUrl()

Get the current page URL

public getCurrentUrl() : string|null
Return values
string|null

getFirst()

Fetch the first page

public getFirst() : self|null
Return values
self|null

getFirstUrl()

Get the first page URL

public getFirstUrl() : string|null
Return values
string|null

getJsonData()

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|null

getLastUrl()

Get the last page URL

public getLastUrl() : string|null
Return values
string|null

getLinkHeader()

Get the Link header from the response

public getLinkHeader() : string
Return values
string

getNavigationUrls()

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|null

getNextUrl()

Get the next page URL

public getNextUrl() : string|null
Return values
string|null

getPaginationInfo()

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|null

getPrev()

Fetch the previous page

public getPrev() : self|null
Return values
self|null

getPrevUrl()

Get the previous page URL

public getPrevUrl() : string|null
Return values
string|null

getResponse()

Get the underlying HTTP response

public getResponse() : ResponseInterface
Return values
ResponseInterface

getTotalPages()

Get the total number of pages

public getTotalPages() : int|null
Return values
int|null

getUrl()

Get URL for specific relation

public getUrl(string $relation) : string|null
Parameters
$relation : string

The relation (next, prev, first, last, current)

Return values
string|null

hasNext()

Check if there is a next page

public hasNext() : bool
Return values
bool

hasPrev()

Check if there is a previous page

public hasPrev() : bool
Return values
bool

hasRelation()

Check if relation exists in Link header

public hasRelation(string $relation) : bool
Parameters
$relation : string

The relation to check

Return values
bool

fetchUrl()

Fetch a specific page by URL

private fetchUrl(string $url) : self|null
Parameters
$url : string

The URL to fetch

Return values
self|null

parseLinkHeader()

Parse Link header and extract navigation URLs

private parseLinkHeader() : array<string|int, string>
Return values
array<string|int, string>

        
On this page

Search results