\smtech\CanvasPestCanvasArray

An object to represent a list of Canvas Objects returned as a response from the Canvas API.

Summary

Methods
Properties
Constants
__construct()
count()
getArrayCopy()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
current()
key()
next()
rewind()
valid()
serialize()
unserialize()
No public properties found
MAXIMUM_PER_PAGE
parsePageLinks()
pageNumberToKey()
requestPageNumber()
requestAllPages()
$api
N/A
No private methods found
$endpoint
$pagination
$paginationPerPage
$data
$page
$key
N/A

Constants

MAXIMUM_PER_PAGE

MAXIMUM_PER_PAGE

The maximum supported number of responses per page

Properties

$endpoint

$endpoint : string

Type

string — API endpoint whose response is represented by this object

$pagination

$pagination : array<mixed,\smtech\CanvasPest\CanvasPageLink>

Type

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

$paginationPerPage

$paginationPerPage : array

Type

array — Cached pagination per each page response

$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, \smtech\CanvasPest\CanvasPest  $canvasPest) 

Construct a CanvasArray

Parameters

string $jsonResponse

A JSON-encoded response array from the Canvas API

\smtech\CanvasPest\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,\smtech\CanvasPest\CanvasObject>

Creates a copy of the CanvasArray

Returns

array<mixed,\smtech\CanvasPest\CanvasObject>

offsetExists()

offsetExists(integer|string  $offset) : boolean

Whether an offset exists

Parameters

integer|string $offset

Returns

boolean

offsetGet()

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

Offset to retrieve

Parameters

integer|string $offset

Returns

\smtech\CanvasPest\CanvasObject|null

offsetSet()

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

Assign a value to the specified offset

Parameters

integer|string $offset
\smtech\CanvasPest\CanvasObject $value

Throws

\smtech\CanvasPest\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

\smtech\CanvasPest\CanvasArray_Exception

IMMUTABLE All calls to this method will cause an exception

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

parsePageLinks()

parsePageLinks(boolean|array<mixed,string>  $headers = false) : array<mixed,\smtech\CanvasPest\CanvasPageLink>

Parse the API response link headers into pagination information

Parameters

boolean|array<mixed,string> $headers

(Optional, defaults to $this->api->lastHeader('link'))

Returns

array<mixed,\smtech\CanvasPest\CanvasPageLink>

pageNumberToKey()

pageNumberToKey(integer  $pageNumber) : integer|false

Convert a page number to an array key

Parameters

integer $pageNumber

1-indexed page number

Returns

integer|false

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)