Collection

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.

package

Default

Methods

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

__construct(array<mixed,\phpDocumentor\Descriptor\DescriptorAbstract>|array<mixed,mixed> $items = array()) 

Arguments

$items

array<mixed,\phpDocumentor\Descriptor\DescriptorAbstract>|array<mixed,mixed>

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

__get(string $name) : mixed

Arguments

$name

string

Response

mixed

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

add(\phpDocumentor\Descriptor\DescriptorAbstract|mixed $item) : void

Empties the collection.

clear() : void

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

count() : integer

Response

integer

Retrieves a specific item from the Collection with its index.

get(string|integer $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.

Arguments

$index

string|integer

$valueIfEmpty

mixed

If the index does not exist it will be created with this value and returned.

Response

mixed

The contents of the element with the given index and the provided default if the key doesn't exist.

Retrieves all items from this collection as PHP Array.

getAll() : array<mixed,mixed>

Response

array<mixed,mixed>

Retrieves an iterator to traverse this object.

getIterator() : \Traversable|\ArrayIterator

Response

\Traversable|\ArrayIterator

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

merge(\phpDocumentor\Descriptor\Collection $collection) : \phpDocumentor\Descriptor\Collection

Checks whether an item in this collection exists.

offsetExists(string|integer $offset) : boolean

Arguments

$offset

string|integer

The index to check on.

Response

boolean

Retrieves an item from the collection with the given index.

offsetGet(string|integer $offset) : mixed

Arguments

$offset

string|integer

The offset to retrieve.

Response

mixed

Sets an item at the given index.

offsetSet(string|integer $offset, mixed $value) : void
Throws
\InvalidArgumentException

if the key is null or an empty string.

Arguments

$offset

string|integer

The offset to assign the value to.

$value

mixed

The value to set.

Removes an item with the given index from the collection.

offsetUnset(string|integer $offset) : void

Arguments

$offset

string|integer

The offset to unset.

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

set(string|integer $index, \phpDocumentor\Descriptor\DescriptorAbstract|mixed|null $item) : void

Arguments

$index

string|integer

An index value to recognize this item with.

$item

\phpDocumentor\Descriptor\DescriptorAbstract|mixed|null

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

Properties

items

items : array<mixed,mixed>
var

Type(s)

array<mixed,mixed>