Elgg  Version 6.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Elgg\Collections\Collection Class Reference

A collection of unique items. More...

Inheritance diagram for Elgg\Collections\Collection:
Elgg\Collections\CollectionInterface Elgg\Menu\MenuItems Elgg\Menu\PreparedMenu Elgg\Menu\MenuSection

Public Member Functions

 __construct ($items=[], $item_class=null)
 Constructor. More...
 
 all ()
 {Returns all collection items by reference.
Returns
CollectionItemInterface[]
} More...
 
 count ()
 {Count collection items.
Returns
int
} More...
 
 add ($item)
 {Add a new item to collection.
Parameters
CollectionItemInterface$itemItem
Returns
static
} More...
 
 get ($id)
 {Get an item by its ID.
Parameters
string | int$idID
Returns
CollectionItemInterface|null
} More...
 
 has ($id)
 {Check if collection has an item with a given ID.
Parameters
string | int$idID
Returns
bool
} More...
 
 remove ($id)
 {Remove item from collection by its ID.
Parameters
string | int$idID
Returns
static
} More...
 
 fill ($items)
 {Replace collection items.
Parameters
CollectionItemInterface[]|Collection$items Items
Returns
static
} More...
 
 merge ($items)
 {Add new items to collection, replacing items with matching IDs.
Parameters
CollectionItemInterface[]|Collection$items Items
Returns
static
} More...
 
 filter (callable $callback=null)
 {Filter collection items using a custom filter Returns a new collection instance.
Parameters
callable$callbackFilter
Returns
static
} More...
 
 sort (callable $callback=null)
 {Sort fields using custom callable If not provided, will sort items by priority.
Parameters
callable$callbackSorter
Returns
static
} More...
 
 walk (callable $callback)
 Walk through members of the collection and apply a callback. More...
 
 map (callable $callback)
 {Walk through all items in the collection and apply a callback.
Parameters
callable$callbackMapper
Returns
mixed
} More...
 
 offsetExists ($offset)
 ArrayAccess interface functions. More...
 
 offsetGet ($offset)
 {} More...
 
 offsetSet ($offset, $value)
 {} More...
 
 offsetUnset ($offset)
 {} More...
 
 current ()
 SeekableIterator interface functions. More...
 
 next ()
 {} More...
 
 key ()
 {} More...
 
 valid ()
 {} More...
 
 rewind ()
 {} More...
 
 seek ($offset)
 {} More...
 

Protected Member Functions

 assertValidItem ($item)
 Validate if item is a valid collection item. More...
 

Protected Attributes

 $items = []
 
 $item_class
 
 $position
 

Detailed Description

A collection of unique items.

Definition at line 11 of file Collection.php.

Constructor & Destructor Documentation

Elgg\Collections\Collection::__construct (   $items = [],
  $item_class = null 
)

Constructor.

Parameters
CollectionItemInterface[]$items Items
string$item_classMember class Restrict members of the collection to instances of this class

Definition at line 38 of file Collection.php.

Member Function Documentation

Elgg\Collections\Collection::add (   $item)

{Add a new item to collection.

Parameters
CollectionItemInterface$itemItem
Returns
static
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 86 of file Collection.php.

Elgg\Collections\Collection::all ( )

{Returns all collection items by reference.

Returns
CollectionItemInterface[]
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 71 of file Collection.php.

Elgg\Collections\Collection::assertValidItem (   $item)
protected

Validate if item is a valid collection item.

Parameters
mixed$itemItem
Returns
void
Exceptions

Definition at line 60 of file Collection.php.

Elgg\Collections\Collection::count ( )

{Count collection items.

Returns
int
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 79 of file Collection.php.

Elgg\Collections\Collection::current ( )

SeekableIterator interface functions.

{}

Definition at line 259 of file Collection.php.

Elgg\Collections\Collection::fill (   $items)

{Replace collection items.

Parameters
CollectionItemInterface[]|Collection$items Items
Returns
static
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 118 of file Collection.php.

Elgg\Collections\Collection::filter ( callable  $callback = null)

{Filter collection items using a custom filter Returns a new collection instance.

Parameters
callable$callbackFilter
Returns
static
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 141 of file Collection.php.

Elgg\Collections\Collection::get (   $id)

{Get an item by its ID.

Parameters
string | int$idID
Returns
CollectionItemInterface|null
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 97 of file Collection.php.

Elgg\Collections\Collection::has (   $id)

{Check if collection has an item with a given ID.

Parameters
string | int$idID
Returns
bool
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 104 of file Collection.php.

Elgg\Collections\Collection::key ( )

{}

Definition at line 277 of file Collection.php.

Elgg\Collections\Collection::map ( callable  $callback)

{Walk through all items in the collection and apply a callback.

Parameters
callable$callbackMapper
Returns
mixed
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 196 of file Collection.php.

Elgg\Collections\Collection::merge (   $items)

{Add new items to collection, replacing items with matching IDs.

Parameters
CollectionItemInterface[]|Collection$items Items
Returns
static
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 130 of file Collection.php.

Elgg\Collections\Collection::next ( )

{}

Definition at line 269 of file Collection.php.

Elgg\Collections\Collection::offsetExists (   $offset)

ArrayAccess interface functions.

{}

Definition at line 215 of file Collection.php.

Elgg\Collections\Collection::offsetGet (   $offset)

{}

Definition at line 223 of file Collection.php.

Elgg\Collections\Collection::offsetSet (   $offset,
  $value 
)

{}

Definition at line 231 of file Collection.php.

Elgg\Collections\Collection::offsetUnset (   $offset)

{}

Definition at line 242 of file Collection.php.

Elgg\Collections\Collection::remove (   $id)

{Remove item from collection by its ID.

Parameters
string | int$idID
Returns
static
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 111 of file Collection.php.

Elgg\Collections\Collection::rewind ( )

{}

Definition at line 297 of file Collection.php.

Elgg\Collections\Collection::seek (   $offset)

{}

Definition at line 305 of file Collection.php.

Elgg\Collections\Collection::sort ( callable  $callback = null)

{Sort fields using custom callable If not provided, will sort items by priority.

Parameters
callable$callbackSorter
Returns
static
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 154 of file Collection.php.

Elgg\Collections\Collection::valid ( )

{}

Definition at line 287 of file Collection.php.

Elgg\Collections\Collection::walk ( callable  $callback)

Walk through members of the collection and apply a callback.

Unlike CollectionInterface::map(), this method does not return the result of mapping, rather returns the exact same instance of the collection after walking through its members by reference

See also
CollectionInterface::map()
Parameters
callable$callbackCallback function
Returns
static

Implements Elgg\Collections\CollectionInterface.

Definition at line 185 of file Collection.php.

Member Data Documentation

Elgg\Collections\Collection::$item_class
protected

Definition at line 24 of file Collection.php.

Elgg\Collections\Collection::$items = []
protected

Definition at line 19 of file Collection.php.

Elgg\Collections\Collection::$position
protected

Definition at line 29 of file Collection.php.


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