Constants

MAXIMUM_PER_PAGE

MAXIMUM_PER_PAGE

The maximum supported number of responses per page

Properties

$api

$api : \CanvasPest

Type

\CanvasPest — Canvas API (for paging through the array)

$endpoint

$endpoint : string

Type

string — API endpoint whose response is represented by this object

$pagination

$pagination : array<mixed,\CanvasPageLink>

Type

array<mixed,\CanvasPageLink> — The canonical (first, last, next, prev, current) pages relative to the current page of responses

$data

$data : array<mixed,\CanvasObject>

Type

array<mixed,\CanvasObject> — Backing store

$page

$page : integer

Type

integer — Page number corresponding to current $key

$key

$key : integer

Type

integer — Current key-value of iterator

Methods

__construct()

__construct(string  $jsonResponse, \CanvasPest  $canvasPest) : void

Construct a CanvasArray

Parameters

string $jsonResponse

A JSON-encoded response array from the Canvas API

\CanvasPest $canvasPest

An API object for making pagination calls

count()

count() : integer

Get the number of CanvasObjects in the Canvas response

Returns

integer

getArrayCopy()

getArrayCopy() : array<mixed,\CanvasObject>

Creates a copy of the CanvasArray

Returns

array<mixed,\CanvasObject>

offsetExists()

offsetExists(integer|string  $offset) : boolean

Whether an offset exists

Parameters

integer|string $offset

Returns

boolean

offsetGet()

offsetGet(integer|string  $offset) : \CanvasObject|null

Offset to retrieve

Parameters

integer|string $offset

Returns

\CanvasObject|null

offsetSet()

offsetSet(integer|string  $offset, \CanvasObject  $value) : void

Assign a value to the specified offset

Parameters

integer|string $offset
\CanvasObject $value

Throws

\CanvasArray_Exception

IMMUTABLE All calls to this method will cause an exception

offsetUnset()

offsetUnset(integer|string  $offset) : void

Unset an offset

Parameters

integer|string $offset

Throws

\CanvasArray_Exception

IMMUTABLE All calls to this method will cause an exception

current()

current() : \CanvasObject

Return the current element

Returns

\CanvasObject

key()

key() : integer

Return the key of the current element

Returns

integer

next()

next() : void

Move forward to next element

rewind()

rewind() : void

Rewind the iterator to the first element

valid()

valid() : boolean

Checks if current position is valid

Returns

boolean

serialize()

serialize() : string

String representation of CanvasArray

Returns

string

unserialize()

unserialize(string  $data) : string

Construct a CanvasArray from its string representation

The data in the unserialized CanvasArray is static and cannot be refreshed, as the CanvasPest API connection is not serialized to preserve the security of API access tokens.

Parameters

string $data

Returns

string

pageNumberToKey()

pageNumberToKey(integer  $pageNumber) : integer

Convert a page number to an array key

Parameters

integer $pageNumber

1-indexed page number

Throws

\CanvasArray_Exception

INVALID_PAGE_NUMBER If $pageNumber < 1

Returns

integer

keyToPageNumber()

keyToPageNumber(integer  $key) : integer

Convert an array key to a page number

Parameters

integer $key

Non-negative array key

Throws

\CanvasArray_Exception

INVALID_ARRAY_KEY If $key < 0

Returns

integer

requestPageNumber()

requestPageNumber(integer  $pageNumber, boolean  $forceRefresh = false) : boolean

Request a page of responses from the API

A page of responses will be requested if it appears that that page has not yet been loaded (tested by checking if the initial element of the page has been initialized in the $data array).

Parameters

integer $pageNumber

Page number to request

boolean $forceRefresh

(Optional) Force a refresh of backing data, even if cached (defaults to FALSE)

Returns

boolean —

TRUE if the page is requested, FALSE if it is already cached (and therefore not requested)

requestAllPages()

requestAllPages(boolean  $forceRefresh = false) : void

Request all pages from API

This stores the entire API response locally, in preparation for, most likely, serializing this object.

Parameters

boolean $forceRefresh

(Optional) Force a refresh of backing data, even if cached (defaults to FALSE)

rewindToPageNumber()

rewindToPageNumber(integer  $pageNumber, boolean  $forceRefresh = false) : void

Rewind the iterator to a specific page of data

If the page of data is already cached, it will not (by default) be reloaded from the API, although this can be overridden with the $forceRefresh parameter.

Parameters

integer $pageNumber

Page number to rewind to

boolean $forceRefresh

(Optional) Defaults to FALSE