Provides an abstraction for working with ordered sets of objects Collection objects are used whenever there are multiples; for example,
multiple objects in a container, or multiple servers in a service.
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.
Return value
Type
Description
\OpenCloud\Common\Base
the first item in the set
Tags
Name
Description
api
Next(
)
:
\OpenCloud\Common\Base
Description
Returns the next item in the page
Return value
Type
Description
\OpenCloud\Common\Base
the next item or FALSE if at the end of the page
Tags
Name
Description
api
NextPage(
)
:
\OpenCloud\Common\Collection
Description
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());
Return value
Type
Description
\OpenCloud\Common\Collection
if there are more pages of results, otherwise FALSE
Tags
Name
Description
api
Reset(
)
:
void
Description
Resets the pointer to the beginning, but does NOT return the first item
Return value
Type
Description
void
Tags
Name
Description
api
Select(
callable
$testfunc,
)
:
n/a
Description
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.
Arguments
Name
Type
Description
Default
$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).
Return value
Type
Description
n/a
n/a
Tags
Name
Description
api
returns
void
throws
if callback doesn't return a boolean value
Service(
)
:
\OpenCloud\Common\Service
Description
Retrieves the service associated with the Collection
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
Arguments
Name
Type
Description
Default
$callback
callable
the name of the function (or array of
object, function name)
$url
string
the URL of the next page of results
Return value
Type
Description
void
Size(
)
:
integer
Description
Returns the number of items in the page 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 value
Type
Description
integer
The number of items in the set
Tags
Name
Description
api
Sort(
string
$keyname
= 'id',
)
:
void
Description
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).
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.
Arguments
Name
Type
Description
Default
$service
\OpenCloud\Common\Service
the service associated with the collection
$itemclass
string
the Class of each item in the collection
(assumed to be the name of the factory method)
Metadata The Metadata class represents either Server or Image metadata
Nova Nova is an abstraction layer for the OpenStack compute service.
ObjectStore Intermediate (abstract) class to implement shared
features of all object-storage classes
PersistentObject represents an object that has the ability to be
retrieved, created, updated, and deleted.
Service This class defines a "service"—a relationship between a specific OpenStack
and a provided service, represented by a URL in the service catalog.
ServiceCatalogItem Holds information on a single service from the Service Catalog
Curl The CurlRequest class is a simple wrapper to CURL functions. Not only does
this permit stubbing of the interface as described under the HttpRequest
interface, it could potentially allow us to replace the interface methods
with other function calls in the future.
HttpRequestInterface The HttpRequest interface defines methods for wrapping CURL; this allows
those methods to be stubbed out for unit testing, thus allowing us to
test without actually making live calls.
Response
Blank The HttpResponse returns an object with status information, separated
headers, and any response body necessary.
Http The HttpResponse returns an object with status information, separated
headers, and any response body necessary.
Compute
Flavor The Flavor class represents a flavor defined by the Compute service
Image The Image class represents a stored machine image returned by the
Compute service.
Network The Network class represents a single virtual network
Server The Server class represents a single server node.
Record The Record class represents a single domain record
Service This class defines a "service"—a relationship between a specific OpenStack
and a provided service, represented by a URL in the service catalog.
Subdomain The Subdomain is basically another domain, albeit one that is a child of
a parent domain. In terms of the code involved, the JSON is slightly
different than a top-level domain, and the parent is a domain instead of
the DNS service itself.
Database
Database This class represents a Database in the Rackspace "Red Dwarf"
database-as-a-service product.
Instance Instance represents an instance of DbService, similar to a Server in a
Compute service
Service The Rackspace Database As A Service (aka "Red Dwarf")
User This class represents a User in the Rackspace "Red Dwarf"
database-as-a-service product.
LoadBalancer
Algorithm sub-resource to manage algorithms (read-only)
AllowedDomain sub-resource to manage allowed domains
BillableLoadBalancer used to get a list of billable load balancers for a specific date range
LoadBalancer The LoadBalancer class represents a single load balancer
Protocol sub-resource to manage protocols (read-only)
Node information on a single node in the load balancer
NodeEvent a single node event, usually called as part of a Collection
Readonly This defines a read-only SubResource - one that cannot be created, updated,
or deleted. Many subresources are like this, and this simplifies their
class definitions.
Stats Stats returns statistics about the load balancer
SubResource SubResource is an abstract class that handles subresources of a
LoadBalancer object; for example, the
`/loadbalancers/{id}/errorpage`. Since most of the subresources are
handled in a similar manner, this consolidates the functions.
Curl The CurlRequest class is a simple wrapper to CURL functions. Not only does
this permit stubbing of the interface as described under the HttpRequest
interface, it could potentially allow us to replace the interface methods
with other function calls in the future.
DataObject A DataObject is an object in the ObjectStore
Database This class represents a Database in the Rackspace "Red Dwarf"
database-as-a-service product.
HttpRequestInterface The HttpRequest interface defines methods for wrapping CURL; this allows
those methods to be stubbed out for unit testing, thus allowing us to
test without actually making live calls.
Rackspace Rackspace extends the OpenStack class with support for Rackspace's
API key and tenant requirements.
Readonly This defines a read-only SubResource - one that cannot be created, updated,
or deleted. Many subresources are like this, and this simplifies their
class definitions.
Service This class defines a "service"—a relationship between a specific OpenStack
and a provided service, represented by a URL in the service catalog.
Service The Compute class represents the OpenStack Nova service.
Service The Rackspace Database As A Service (aka "Red Dwarf")
Service This class defines a "service"—a relationship between a specific OpenStack
and a provided service, represented by a URL in the service catalog.
Stack The Stack class requires a CloudFormation template and may contain additional
parameters for that template.
Stats Stats returns statistics about the load balancer
SubResource SubResource is an abstract class that handles subresources of a
LoadBalancer object; for example, the
`/loadbalancers/{id}/errorpage`. Since most of the subresources are
handled in a similar manner, this consolidates the functions.
Subdomain The Subdomain is basically another domain, albeit one that is a child of
a parent domain. In terms of the code involved, the JSON is slightly
different than a top-level domain, and the parent is a domain instead of
the DNS service itself.