Collection
Represents an easily accessible collection of elements.
The goal for this class is to allow Descriptors to be easily retrieved and set so that interaction in templates becomes easier.
Interfaces, Classes & Used Traits
- Countable
- IteratorAggregate
- ArrayAccess
Properties
$items Line 39
protected$items : array
Methods
__construct() Line 46
Constructs a new collection object with optionally a series of items, generally Descriptors.
public__construct([array $items = [] ]) : mixed
Parameters
Returns
mixed —
add() Line 58
Adds a new item to this collection, generally a Descriptor.
publicadd(string $item) : void
Parameters
set() Line 70
Sets a new object onto the collection or clear it using null.
publicset(string|int $index, string $item) : void
Parameters
An index value to recognize this item with.
The item to store, generally a Descriptor but may be something else.
get() Line 92
Retrieves a specific item from the Collection with its index.
publicget(string|int $index[, mixed $valueIfEmpty = null ]) : mixed
Please note that this method (intentionally) has the side effect that whenever a key does not exist that it will be created with the value provided by the $valueIfEmpty argument. This will allow for easy initialization during tree building operations.
Parameters
If the index does not exist it will be created with this value and returned.
Returns
mixed —The contents of the element with the given index and the provided default if the key doesn't exist.
Returns
array —
getIterator() Line 116
Retrieves an iterator to traverse this object.
publicgetIterator() : ArrayIterator
Returns
ArrayIterator —<string|int, T>
Returns
int —
__get() Line 144
Retrieves an item as if it were a property of the collection.
public__get(string $name) : mixed
Parameters
Returns
mixed —
offsetExists() Line 154
Checks whether an item in this collection exists.
publicoffsetExists(string|int $offset) : bool
Parameters
The index to check on.
Returns
bool —
offsetGet() Line 168
Retrieves an item from the collection with the given index.
publicoffsetGet(string|int $offset) : mixed
Parameters
The offset to retrieve.
Returns
mixed —
offsetSet() Line 183
Sets an item at the given index.
publicoffsetSet(string|int|null $offset, mixed $value) : void
Parameters
The offset to assign the value to.
The value to set.
Throws
- \InvalidArgumentException
If the key is null or an empty string.
offsetUnset() Line 199
Removes an item with the given index from the collection.
publicoffsetUnset(string|int $offset) : void
Parameters
The offset to unset.
merge() Line 211
Returns a new collection with the items from this collection and the provided combined.
publicmerge(Collection $collection) : Collection
Parameters
should be Collection