PaginationResult
in package
PaginationResult Class
Wrapper class for paginated API responses that provides access to data and pagination metadata. This class encapsulates the results of a paginated API call along with navigation links and metadata extracted from Canvas API Link headers.
Usage:
$result = Course::fetchAllPaginated(['per_page' => 50]);
$courses = $result->getData();
if ($result->hasNext()) {
$nextResult = $result->getNext();
}
echo "Page {$result->getCurrentPage()} of {$result->getTotalPages()}";
Table of Contents
Properties
- $currentPage : int
- Current page number
- $currentUrl : string|null
- URL for the current page of results
- $data : array<string|int, mixed>
- The actual data from the API response
- $firstUrl : string|null
- URL for the first page of results
- $lastUrl : string|null
- URL for the last page of results
- $nextUrl : string|null
- URL for the next page of results
- $perPage : int|null
- Number of items per page
- $prevUrl : string|null
- URL for the previous page of results
- $totalPages : int|null
- Total number of pages (if determinable)
Methods
- __construct() : mixed
- PaginationResult constructor
- fromLinkHeader() : self
- Create PaginationResult from Link header
- getCount() : int
- Get the number of items in the current page
- getCurrentPage() : int
- Get the current page number
- getCurrentUrl() : string|null
- Get the URL for the current page
- getData() : array<string|int, mixed>
- Get the data from the API response
- getFirstUrl() : string|null
- Get the URL for the first page
- getLastUrl() : string|null
- Get the URL for the last page
- getNavigationUrls() : array<string|int, string>
- Get all navigation URLs
- getNextUrl() : string|null
- Get the URL for the next page
- getPerPage() : int|null
- Get the number of items per page
- getPrevUrl() : string|null
- Get the URL for the previous page
- getSummary() : string
- Get pagination summary string
- getTotalPages() : int|null
- Get the total number of pages
- hasMore() : bool
- Check if there are more pages available
- hasNext() : bool
- Check if there is a next page
- hasPrev() : bool
- Check if there is a previous page
- isEmpty() : bool
- Check if the current page is empty
- isFirstPage() : bool
- Check if this is the first page
- isLastPage() : bool
- Check if this is the last page
- toArray() : array<string|int, mixed>
- Convert to array representation
Properties
$currentPage
Current page number
private
int
$currentPage
$currentUrl
URL for the current page of results
private
string|null
$currentUrl
$data
The actual data from the API response
private
array<string|int, mixed>
$data
$firstUrl
URL for the first page of results
private
string|null
$firstUrl
$lastUrl
URL for the last page of results
private
string|null
$lastUrl
$nextUrl
URL for the next page of results
private
string|null
$nextUrl
$perPage
Number of items per page
private
int|null
$perPage
$prevUrl
URL for the previous page of results
private
string|null
$prevUrl
$totalPages
Total number of pages (if determinable)
private
int|null
$totalPages
Methods
__construct()
PaginationResult constructor
public
__construct(array<string|int, mixed> $data[, array<string|int, string> $navigationLinks = [] ][, int $currentPage = 1 ][, int|null $totalPages = null ][, int|null $perPage = null ]) : mixed
Parameters
- $data : array<string|int, mixed>
-
The API response data
- $navigationLinks : array<string|int, string> = []
-
Associative array of navigation URLs
- $currentPage : int = 1
-
Current page number
- $totalPages : int|null = null
-
Total number of pages
- $perPage : int|null = null
-
Items per page
fromLinkHeader()
Create PaginationResult from Link header
public
static fromLinkHeader(array<string|int, mixed> $data, string $linkHeader) : self
Parameters
- $data : array<string|int, mixed>
-
The API response data
- $linkHeader : string
-
The Link header string
Return values
selfgetCount()
Get the number of items in the current page
public
getCount() : int
Return values
intgetCurrentPage()
Get the current page number
public
getCurrentPage() : int
Return values
intgetCurrentUrl()
Get the URL for the current page
public
getCurrentUrl() : string|null
Return values
string|nullgetData()
Get the data from the API response
public
getData() : array<string|int, mixed>
Return values
array<string|int, mixed>getFirstUrl()
Get the URL for the first page
public
getFirstUrl() : string|null
Return values
string|nullgetLastUrl()
Get the URL for the last page
public
getLastUrl() : string|null
Return values
string|nullgetNavigationUrls()
Get all navigation URLs
public
getNavigationUrls() : array<string|int, string>
Return values
array<string|int, string>getNextUrl()
Get the URL for the next page
public
getNextUrl() : string|null
Return values
string|nullgetPerPage()
Get the number of items per page
public
getPerPage() : int|null
Return values
int|nullgetPrevUrl()
Get the URL for the previous page
public
getPrevUrl() : string|null
Return values
string|nullgetSummary()
Get pagination summary string
public
getSummary() : string
Return values
stringgetTotalPages()
Get the total number of pages
public
getTotalPages() : int|null
Return values
int|nullhasMore()
Check if there are more pages available
public
hasMore() : bool
Return values
boolhasNext()
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
boolisEmpty()
Check if the current page is empty
public
isEmpty() : bool
Return values
boolisFirstPage()
Check if this is the first page
public
isFirstPage() : bool
Return values
boolisLastPage()
Check if this is the last page
public
isLastPage() : bool
Return values
booltoArray()
Convert to array representation
public
toArray() : array<string|int, mixed>