Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | List of all members
Elgg\Structs\Collection Interface Reference

A read-only interface to a (possibly mutable) group of items. More...

Inheritance diagram for Elgg\Structs\Collection:
Elgg\Structs\Collection\InMemory

Public Member Functions

 filter (callable $filter)
 Returns a new collection only containing the elements which pass the filter. More...
 
 contains ($item)
 Returns true iff the item is in this collection at least once. More...
 
 map (callable $mapper)
 Take items of the collection and return a new collection with all the items having the $mapper applied to them. More...
 

Detailed Description

A read-only interface to a (possibly mutable) group of items.

Read-only provides some nice guarantees that can be harnessed for things like caching, lazy evaluation, respecting HTTP semantics of GET/HEAD, etc.

We do not extend ArrayAccess, because:

Extensions may provide one or more of these features.

TODO(ewinslow): If PHP had generics support, we'd add that here.

DO NOT EXTEND OR IMPLEMENT this interface outside of this package. Doing so would cause additions to the API to be breaking changes, which is not what we want. You have a couple of options for how to proceed:

Since
1.10

private

Definition at line 33 of file Collection.php.

Member Function Documentation

Elgg\Structs\Collection::contains (   $item)

Returns true iff the item is in this collection at least once.

Parameters
mixed$itemThe object or value to check for
Returns
boolean

Implemented in Elgg\Structs\Collection\InMemory.

Elgg\Structs\Collection::filter ( callable  $filter)

Returns a new collection only containing the elements which pass the filter.

Parameters
callable$filterReceives an item. Return true to keep the item.
Returns
Collection

Implemented in Elgg\Structs\Collection\InMemory.

Elgg\Structs\Collection::map ( callable  $mapper)

Take items of the collection and return a new collection with all the items having the $mapper applied to them.

The callable is not guaranteed to execute immediately for each item.

Parameters
callable$mapperReturns the mapped value
Returns
Collection

Implemented in Elgg\Structs\Collection\InMemory.


The documentation for this interface was generated from the following file: