Elgg  Version 3.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)
 {} More...
 
 offsetGet ($offset)
 {} More...
 
 offsetSet ($offset, $value)
 {} More...
 
 offsetUnset ($offset)
 {} More...
 
 current ()
 {} More...
 
 next ()
 {} More...
 
 key ()
 {} More...
 
 valid ()
 {} More...
 
 rewind ()
 {} More...
 
 seek ($position)
 {} More...
 

Protected Member Functions

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

Protected Attributes

 $items = []
 
 $item_class
 

Detailed Description

A collection of unique items.

Definition at line 14 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 36 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 82 of file Collection.php.

Elgg\Collections\Collection::all ( )

{Returns all collection items by reference.

Returns
CollectionItemInterface[]
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 68 of file Collection.php.

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

Validate if item is a valid collection item.

Parameters
mixed$itemItem
Returns
void

Definition at line 57 of file Collection.php.

Elgg\Collections\Collection::count ( )

{Count collection items.

Returns
int
}

Implements Elgg\Collections\CollectionInterface.

Definition at line 75 of file Collection.php.

Elgg\Collections\Collection::current ( )

{}

Definition at line 237 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 114 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 137 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 93 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 100 of file Collection.php.

Elgg\Collections\Collection::key ( )

{}

Definition at line 251 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 192 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 126 of file Collection.php.

Elgg\Collections\Collection::next ( )

{}

Definition at line 244 of file Collection.php.

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

{}

Definition at line 206 of file Collection.php.

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

{}

Definition at line 213 of file Collection.php.

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

{}

Definition at line 220 of file Collection.php.

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

{}

Definition at line 230 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 107 of file Collection.php.

Elgg\Collections\Collection::rewind ( )

{}

Definition at line 265 of file Collection.php.

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

{}

Definition at line 272 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 150 of file Collection.php.

Elgg\Collections\Collection::valid ( )

{}

Definition at line 258 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 181 of file Collection.php.

Member Data Documentation

Elgg\Collections\Collection::$item_class
protected

Definition at line 27 of file Collection.php.

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

Definition at line 22 of file Collection.php.


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