Overview
  • Namespace
  • Class

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CDN
      • Resource
    • CloudMonitoring
      • Collection
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Log
      • Resource
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Collection
      • Resource
    • Identity
      • Constants
      • Resource
    • Image
      • Enum
      • Resource
        • JsonPatch
        • Schema
    • LoadBalancer
      • Collection
      • Enum
      • Resource
    • Networking
      • Resource
    • ObjectStore
      • Constants
      • Enum
      • Exception
      • Resource
      • Upload
    • Orchestration
      • Resource
    • Queues
      • Collection
      • Exception
      • Resource
    • Volume
      • Resource

Classes

  • ArrayAccess
  • Base
  • Collection
  • Lang
  • Metadata
  • PersistentObject

Class Collection

OpenCloud\Common\Base
Extended by OpenCloud\Common\Collection
Namespace: OpenCloud\Common
Deprecated
Codecoverageignore
Located at OpenCloud/Common/Collection.php

Methods summary

public
# __construct( Service $service, string $class, array $array = array() )

A Collection is an array of objects

A Collection is an array of objects

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
  • the service associated with the collection
$class

$itemclass - the Class of each item in the collection (assumed to be the name of the factory method)

$array
$arr - the input array
public array
# getItemList( )

Retrieve the entire data array.

Retrieve the entire data array.

Returns

array
public
# setService( Service|OpenCloud\Common\PersistentObject $service )

Set the service.

Set the service.

Parameters

$service
public Service
# getService( )

Retrieves the service associated with the Collection

Retrieves the service associated with the Collection

Returns

Service
public
# setNextPageCallback( callable $callback, string $url )

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

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

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

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

$url
the URL of the next page of results
public integer
# count( )

Returns the number of items in the collection

Returns the number of items in the collection

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.

Returns

integer
public
# size( )

Pseudonym for count()

Pseudonym for count()

Codecoverageignore

public
# reset( )

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

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

Api

public OpenCloud\Common\Base
# first( )

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

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

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

Returns

OpenCloud\Common\Base
the first item in the set

Api

public mixed
# getItem( mixed $pointer )

Return the item at a particular point of the array.

Return the item at a particular point of the array.

Parameters

$pointer
$offset

Returns

mixed
public
# addItem( mixed $item )

Add an item to this collection

Add an item to this collection

Parameters

$item
public OpenCloud\Common\Base
# next( )

Returns the next item in the page

Returns the next item in the page

Returns

OpenCloud\Common\Base
the next item or FALSE if at the end of the page

Api

public
# sort( string $keyname = 'id' )

sorts the collection on a specified key

sorts the collection on a specified key

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
the name of the field to use as the sort key

Api

public
# select( callable $testfunc )

selects only specified items from the Collection

selects only specified items from the Collection

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

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).

Throws

DomainError
if callback doesn't return a boolean value

Api

Returns

void
public OpenCloud\Common\Collection
# nextPage( )

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

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

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());

Returns

OpenCloud\Common\Collection
if there are more pages of results, otherwise FALSE

Api

Methods inherited from OpenCloud\Common\Base

__call(), checkJsonError(), generateUuid(), getInstance(), getLogger(), hasLogger(), makeResourceIteratorOptions(), populate(), setLogger(), stripNamespace(), toCamel(), toUnderscores(), url()

Constants summary

Constants inherited from OpenCloud\Common\Base

PATCH_CONTENT_TYPE

API documentation generated by ApiGen