\phpDocumentor\DescriptorCollection

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.

Summary

Methods
Properties
Constants
__construct()
add()
set()
get()
fetch()
getAll()
getIterator()
count()
clear()
__get()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
merge()
filter()
fromClassString()
No public properties found
No constants found
No protected methods found
$items
N/A
No private methods found
No private properties found
N/A

Properties

$items

$items : \phpDocumentor\Descriptor\T[]

Type

T[]

Methods

__construct()

__construct(\phpDocumentor\Descriptor\T[]  $items = []) : mixed

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

Parameters

\phpDocumentor\Descriptor\T[] $items

Returns

mixed —

add()

add(\phpDocumentor\Descriptor\T  $item) : void

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

Parameters

\phpDocumentor\Descriptor\T $item

set()

set(string|int  $index, \phpDocumentor\Descriptor\T  $item) : void

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

Parameters

string|int $index

An index value to recognize this item with.

\phpDocumentor\Descriptor\T $item

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

get()

get(string|int  $index) : \phpDocumentor\Descriptor\T

Retrieves a specific item from the Collection with its index. If index is not found, an exception is thrown

Parameters

string|int $index

Returns

\phpDocumentor\Descriptor\T —

The contents of the element with the given index

fetch()

fetch(string|int  $index, ?\phpDocumentor\Descriptor\TChild  $valueIfEmpty = null) : \phpDocumentor\Descriptor\TChild

Retrieves a specific item from the Collection with its index.

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

string|int $index
?\phpDocumentor\Descriptor\TChild $valueIfEmpty

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

Returns

\phpDocumentor\Descriptor\TChild —

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

getAll()

getAll() : \phpDocumentor\Descriptor\T[]

Retrieves all items from this collection as PHP Array.

Returns

\phpDocumentor\Descriptor\T[] —

getIterator()

getIterator() : \ArrayIterator<string|int,\phpDocumentor\Descriptor\T>

Retrieves an iterator to traverse this object.

Returns

\ArrayIterator

count()

count() : int

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

Returns

int —

clear()

clear() : void

Empties the collection.

__get()

__get(string  $name) : mixed

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

Parameters

string $name

Returns

mixed —

offsetExists()

offsetExists(string|int  $offset) : bool

Checks whether an item in this collection exists.

Parameters

string|int $offset

The index to check on.

Returns

bool —

offsetGet()

offsetGet(string|int  $offset) : ?\phpDocumentor\Descriptor\T

Retrieves an item from the collection with the given index.

Parameters

string|int $offset

The offset to retrieve.

Returns

?\phpDocumentor\Descriptor\T —

offsetSet()

offsetSet(string|int|null  $offset, \phpDocumentor\Descriptor\T  $value) : void

Sets an item at the given index.

Parameters

string|int|null $offset

The offset to assign the value to.

\phpDocumentor\Descriptor\T $value

The value to set.

Throws

\InvalidArgumentException

If the key is null or an empty string.

offsetUnset()

offsetUnset(string|int  $offset) : void

Removes an item with the given index from the collection.

Parameters

string|int $offset

The offset to unset.

merge()

merge(\phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\T>  $collection) : \phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\T>

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

Parameters

\phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\T> $collection

Returns

\phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\T> —

filter()

filter(class-string<\phpDocumentor\Descriptor\F>  $className) : \phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\F>

Parameters

class-string<\phpDocumentor\Descriptor\F> $className

Returns

\phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\F> —

fromClassString()

fromClassString(class-string<\phpDocumentor\Descriptor\C>  $classString, \phpDocumentor\Descriptor\C[]  $elements = []) : \phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\C>

Parameters

class-string<\phpDocumentor\Descriptor\C> $classString
\phpDocumentor\Descriptor\C[] $elements

Returns

\phpDocumentor\Descriptor\Collection<\phpDocumentor\Descriptor\C> —