Collection

in package
Implements Countable, IteratorAggregate, ArrayAccess

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
template

T

template-implements

ArrayAccess <string|int, T>

template-implements

IteratorAggregate <string|int, T>

Properties

protected$items  : array                

Methods

Constructs a new collection object with optionally a series of items, generally Descriptors.

public__construct([array $items = [] ]) : mixed

Parameters

$items : array = []

Returns

mixed

Adds a new item to this collection, generally a Descriptor.

publicadd(string $item) : void

Parameters

$item : string

Sets a new object onto the collection or clear it using null.

publicset(string|int $index, string $item) : void

Parameters

$index : string|int

An index value to recognize this item with.

$item : string

The item to store, generally a Descriptor but may be something else.

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

$index : string|int
$valueIfEmpty : mixed = null

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.

phpstan-param

T $valueIfEmpty

phpstan-return

T

Retrieves all items from this collection as PHP Array.

publicgetAll() : array

Returns

array

Retrieves an iterator to traverse this object.

publicgetIterator() : ArrayIterator

Returns

ArrayIterator

<string|int, T>

Returns a count of the number of elements in this collection.

publiccount() : int

Returns

int

Empties the collection.

publicclear() : void

Retrieves an item as if it were a property of the collection.

public__get(string $name) : mixed

Parameters

$name : string

Returns

mixed
phpstan-return

T

Checks whether an item in this collection exists.

publicoffsetExists(string|int $offset) : bool

Parameters

$offset : string|int

The index to check on.

Returns

bool

Retrieves an item from the collection with the given index.

publicoffsetGet(string|int $offset) : mixed

Parameters

$offset : string|int

The offset to retrieve.

Returns

mixed
phpstan-return

T

Sets an item at the given index.

publicoffsetSet(string|int|null $offset, mixed $value) : void

Parameters

$offset : string|int|null

The offset to assign the value to.

$value : mixed

The value to set.

Throws

\InvalidArgumentException

If the key is null or an empty string.

phpstan-param

T $value

Removes an item with the given index from the collection.

publicoffsetUnset(string|int $offset) : void

Parameters

$offset : string|int

The offset to unset.

Returns a new collection with the items from this collection and the provided combined.

publicmerge(Collection $collection) : Collection

Parameters

$collection : Collection

should be Collection but create issues with inherited Descriptors

Returns

Collection

publicfilter(string $className) : Collection

Parameters

$className : string

Returns

Collection

<object&T>

publicstaticfromClassString(string $classString[, array $elements = [] ]) : Collection

Parameters

$classString : string
$elements : array = []

Returns

Collection
template

C