Documentation

Collection extends Base
in package

The root class for all other objects used or defined by this SDK.

Tags
deprecated
codeCoverageIgnore

Table of Contents

PATCH_CONTENT_TYPE  = OpenCloudCommonConstantsMime::JSON_PATCH
$aliases  : array<string|int, mixed>
The aliases configure for the properties of the instance.
$itemClass  : mixed
$itemList  : mixed
$logger  : LoggerInterface
The logger instance
$nextPageCallback  : mixed
$nextPageClass  : mixed
$nextPageUrl  : mixed
$pointer  : mixed
$properties  : array<string|int, mixed>
Holds all the properties added by overloading.
$service  : mixed
$sortKey  : mixed
__call()  : mixed
Intercept non-existent method calls for dynamic getter/setter functionality.
__construct()  : mixed
A Collection is an array of objects
addItem()  : mixed
Add an item to this collection
checkJsonError()  : mixed
Checks the most recent JSON operation for errors.
count()  : int
Returns the number of items in the collection
first()  : Base
Resets the collection pointer back to the first item in the page and returns it
generateUuid()  : mixed
getInstance()  : static
getItem()  : mixed
Return the item at a particular point of the array.
getItemList()  : array<string|int, mixed>
Retrieve the entire data array.
getLogger()  : LoggerInterface
Returns the Logger object.
getService()  : Service
Retrieves the service associated with the Collection
hasLogger()  : bool
makeResourceIteratorOptions()  : mixed
next()  : Base
Returns the next item in the page
nextPage()  : Collection
returns the Collection object for the next page of results, or FALSE if there are no more pages
populate()  : mixed
Populates the current object based on an unknown data type.
reset()  : void
Resets the pointer to the beginning, but does NOT return the first item
select()  : mixed
selects only specified items from the Collection
setLogger()  : $this
Sets the logger.
setNextPageCallback()  : void
for paginated collection, sets the callback function and URL for the next page
setService()  : mixed
Set the service.
size()  : mixed
Pseudonym for count()
sort()  : void
sorts the collection on a specified key
stripNamespace()  : mixed
toCamel()  : mixed
Convert a string to camelCase format.
toUnderscores()  : mixed
Convert string to underscore format.
url()  : mixed
getJsonHeader()  : mixed
getPatchHeaders()  : mixed
getProperty()  : mixed
Grab value out of the data array.
propertyExists()  : bool
Basic check to see whether property exists.
setProperty()  : mixed
We can set a property under three conditions:
checkAttributePrefix()  : bool
Checks the attribute $property and only permits it if the prefix is in the specified $prefixes array
getItemClass()  : mixed
Get item class.
getNextPageCallback()  : mixed
Get next page callback.
getNextPageClass()  : mixed
Get next page class.
getNextPageUrl()  : mixed
Get next page URL.
getSortKey()  : mixed
Get the key that will be used for sorting.
isAccessible()  : bool
Does the property exist in the object variable list (i.e. does it have public or protected visibility?)
setItemClass()  : mixed
Set the resource class name.
setItemList()  : mixed
Set the entire data array.
setNextPageClass()  : mixed
Set next page class.
setSortKey()  : mixed
Set the key that will be used for sorting.
sortCompare()  : mixed
Compares two values of sort keys

Constants

PATCH_CONTENT_TYPE

public mixed PATCH_CONTENT_TYPE = OpenCloudCommonConstantsMime::JSON_PATCH

Properties

$aliases

The aliases configure for the properties of the instance.

protected array<string|int, mixed> $aliases = array()

$nextPageCallback

private mixed $nextPageCallback

$properties

Holds all the properties added by overloading.

private array<string|int, mixed> $properties = array()

Methods

__call()

Intercept non-existent method calls for dynamic getter/setter functionality.

public __call( $method,  $args) : mixed
Parameters
$method :
$args :
Tags
throws
RuntimeException
Return values
mixed

__construct()

A Collection is an array of objects

public __construct(Service $service, mixed $class[, array<string|int, mixed> $array = array() ]) : mixed

Some assumptions:

  • The Collection class assumes that there exists on its service a factory method with the same name of the class. For example, if you create a Collection of class Foobar, it will attempt to call the method parent::Foobar() to create instances of that class.
  • It assumes that the factory method can take an array of values, and it passes that to the method.
Parameters
$service : Service
  • the service associated with the collection
$class : mixed
$array : array<string|int, mixed> = array()
Return values
mixed

addItem()

Add an item to this collection

public addItem(mixed $item) : mixed
Parameters
$item : mixed
Return values
mixed

checkJsonError()

Checks the most recent JSON operation for errors.

public static checkJsonError() : mixed
Tags
throws
JsonError
codeCoverageIgnore
Return values
mixed

count()

Returns the number of items in the collection

public count() : int

For most services, this is the total number of items. If the Collection is paginated, however, this only returns the count of items in the current page of data.

Return values
int

first()

Resets the collection pointer back to the first item in the page and returns it

public first() : Base

This is useful if you're only interested in the first item in the page.

Return values
Base

the first item in the set

generateUuid()

public static generateUuid() : mixed
Return values
mixed

getInstance()

public static getInstance() : static
Return values
static

getItem()

Return the item at a particular point of the array.

public getItem(mixed $pointer) : mixed
Parameters
$pointer : mixed
Return values
mixed

getItemList()

Retrieve the entire data array.

public getItemList() : array<string|int, mixed>
Return values
array<string|int, mixed>

getService()

Retrieves the service associated with the Collection

public getService() : Service
Return values
Service

hasLogger()

public hasLogger() : bool
Return values
bool

makeResourceIteratorOptions()

public makeResourceIteratorOptions(mixed $resource) : mixed
Parameters
$resource : mixed
Return values
mixed

next()

Returns the next item in the page

public next() : Base
Return values
Base

the next item or FALSE if at the end of the page

nextPage()

returns the Collection object for the next page of results, or FALSE if there are no more pages

public nextPage() : Collection

Generally, the structure for a multi-page collection will look like this:

 $coll = $obj->Collection();
 do {
     while ($item = $coll->Next()) {
         // do something with the item
     }
 } while ($coll = $coll->NextPage());
Return values
Collection

if there are more pages of results, otherwise FALSE

populate()

Populates the current object based on an unknown data type.

public populate(mixed $info[, mixed $setObjects = true ]) : mixed
Parameters
$info : mixed
$setObjects : mixed = true
Tags
throws
InvalidArgumentError
Return values
mixed

reset()

Resets the pointer to the beginning, but does NOT return the first item

public reset() : void
Return values
void

select()

selects only specified items from the Collection

public select(callable $testfunc) : mixed

This provides a simple form of filtering on Collections. For each item in the collection, it calls the callback function, passing it the item. If the callback returns TRUE, then the item is retained; if it returns FALSE, then the item is deleted from the collection.

Note that this should not supersede server-side filtering; the Collection::Select() method requires that all of the data for the Collection be retrieved from the server before the filtering is performed; this can be very inefficient, especially for large data sets. This method is mostly useful on smaller-sized sets.

Example: $services = $connection->ServiceList(); $services->Select(function ($item) { return $item->region=='ORD';}); // now the $services Collection only has items from the ORD region

Select() is destructive; that is, it actually removes entries from the collection. For example, if you use Select() to find items with the ID > 10, then use it again to find items that are <= 10, it will return an empty list.

Parameters
$testfunc : callable

a callback function that is passed each item in turn. Note that Select() performs an explicit test for FALSE, so functions like strpos() need to be cast into a boolean value (and not just return the integer).

Tags
returns

void

throws
DomainError

if callback doesn't return a boolean value

Return values
mixed

setNextPageCallback()

for paginated collection, sets the callback function and URL for the next page

public setNextPageCallback(callable $callback, string $url) : void

The callback function should have the signature:

 function Whatever($class, $url, $parent)

and the $url should be the URL of the next page of results

Parameters
$callback : callable

the name of the function (or array of object, function name)

$url : string

the URL of the next page of results

Return values
void

size()

Pseudonym for count()

public size() : mixed
Tags
codeCoverageIgnore
Return values
mixed

sort()

sorts the collection on a specified key

public sort([string $keyname = 'id' ]) : void

Note: only top-level keys can be used as the sort key. Note that this only sorts the data in the current page of the Collection (for multi-page data).

Parameters
$keyname : string = 'id'

the name of the field to use as the sort key

Return values
void

stripNamespace()

public stripNamespace(mixed $namespace) : mixed
Parameters
$namespace : mixed
Return values
mixed

toCamel()

Convert a string to camelCase format.

public toCamel( $string[, bool $capitalise = true ]) : mixed
Parameters
$string :
$capitalise : bool = true

Optional flag which allows for word capitalization.

Return values
mixed

toUnderscores()

Convert string to underscore format.

public toUnderscores( $string) : mixed
Parameters
$string :
Return values
mixed

url()

public url([mixed $path = null ][, array<string|int, mixed> $query = array() ]) : mixed
Parameters
$path : mixed = null
$query : array<string|int, mixed> = array()
Tags
deprecated
Return values
mixed

getJsonHeader()

protected static getJsonHeader() : mixed
Return values
mixed

getPatchHeaders()

protected static getPatchHeaders() : mixed
Return values
mixed

getProperty()

Grab value out of the data array.

protected getProperty(string $property) : mixed
Parameters
$property : string
Return values
mixed

propertyExists()

Basic check to see whether property exists.

protected propertyExists(string $property[, bool $allowRetry = true ]) : bool
Parameters
$property : string

The property name being investigated.

$allowRetry : bool = true

If set to TRUE, the check will try to format the name in underscores because there are sometimes discrepancies between camelCaseNames and underscore_names.

Return values
bool

setProperty()

We can set a property under three conditions:

protected setProperty(mixed $property, mixed $value) : mixed
  1. If it has a concrete setter: setProperty()
  2. If the property exists
  3. If the property name's prefix is in an approved list
Parameters
$property : mixed
$value : mixed
Return values
mixed

checkAttributePrefix()

Checks the attribute $property and only permits it if the prefix is in the specified $prefixes array

private checkAttributePrefix(string $property) : bool

This is to support extension namespaces in some services.

Parameters
$property : string

the name of the attribute

Return values
bool

getItemClass()

Get item class.

private getItemClass() : mixed
Return values
mixed

getNextPageCallback()

Get next page callback.

private getNextPageCallback() : mixed
Return values
mixed

getNextPageClass()

Get next page class.

private getNextPageClass() : mixed
Return values
mixed

getNextPageUrl()

Get next page URL.

private getNextPageUrl() : mixed
Return values
mixed

getSortKey()

Get the key that will be used for sorting.

private getSortKey() : mixed
Return values
mixed

isAccessible()

Does the property exist in the object variable list (i.e. does it have public or protected visibility?)

private isAccessible( $property) : bool
Parameters
$property :
Return values
bool

setItemClass()

Set the resource class name.

private setItemClass(mixed $itemClass) : mixed
Parameters
$itemClass : mixed
Return values
mixed

setItemList()

Set the entire data array.

private setItemList(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>
Return values
mixed

setNextPageClass()

Set next page class.

private setNextPageClass(mixed $nextPageClass) : mixed
Parameters
$nextPageClass : mixed
Return values
mixed

setSortKey()

Set the key that will be used for sorting.

private setSortKey(mixed $sortKey) : mixed
Parameters
$sortKey : mixed
Return values
mixed

sortCompare()

Compares two values of sort keys

private sortCompare(mixed $a, mixed $b) : mixed
Parameters
$a : mixed
$b : mixed
Return values
mixed

Search results