phpDocumentor

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.

Table of Contents

Interfaces

Countable
IteratorAggregate
ArrayAccess

Properties

$items  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructs a new collection object with optionally a series of items, generally Descriptors.
__get()  : mixed
Retrieves an item as if it were a property of the collection.
add()  : void
Adds a new item to this collection, generally a Descriptor.
clear()  : void
Empties the collection.
count()  : int
Returns a count of the number of elements in this collection.
fetch()  : TChild
Retrieves a specific item from the Collection with its index.
filter()  : Collection<string|int, F>
first()  : T|null
fromClassString()  : Collection<string|int, C>
fromInterfaceString()  : Collection<string|int, C>
get()  : T
Retrieves a specific item from the Collection with its index. If index is not found, an exception is thrown
getAll()  : array<string|int, T>
Retrieves all items from this collection as PHP Array.
getIterator()  : ArrayIterator<string|int, T>
Retrieves an iterator to traverse this object.
merge()  : Collection<string|int, T>
Returns a new collection with the items from this collection and the provided combined.
offsetExists()  : bool
Checks whether an item in this collection exists.
offsetGet()  : T|null
Retrieves an item from the collection with the given index.
offsetSet()  : void
Sets an item at the given index.
offsetUnset()  : void
Removes an item with the given index from the collection.
set()  : void
Sets a new object onto the collection or clear it using null.

Properties

$items

protected array<string|int, mixed> $items = []

Methods

__construct()

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

public __construct([array<string|int, T$items = [] ]) : mixed
Parameters
$items : array<string|int, T> = []

__get()

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

public __get(string $name) : mixed
Parameters
$name : string
Tags
phpstan-return

?T

add()

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

public add(T $item) : void
Parameters
$item : T

clear()

Empties the collection.

public clear() : void

count()

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

public count() : int
Attributes
#[ReturnTypeWillChange]
Return values
int

fetch()

Retrieves a specific item from the Collection with its index.

public fetch(string|int $index[, TChild|null $valueIfEmpty = null ]) : TChild

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 : TChild|null = null

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

Tags
psalm-return

($valueIfEmpty is null ? ?TChild : TChild)

phpstan-return

T|TChild

Return values
TChild

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

first()

public first() : T|null
Return values
T|null

fromClassString()

public static fromClassString(C> $classString[, array<string|int, C$elements = [] ]) : Collection<string|int, C>
Parameters
$classString : C>
$elements : array<string|int, C> = []
Return values
Collection<string|int, C>

fromInterfaceString()

public static fromInterfaceString(C> $interfaceString[, array<string|int, C$elements = [] ]) : Collection<string|int, C>
Parameters
$interfaceString : C>
$elements : array<string|int, C> = []
Return values
Collection<string|int, C>

get()

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

public get(string|int $index) : T
Parameters
$index : string|int
Return values
T

The contents of the element with the given index

getAll()

Retrieves all items from this collection as PHP Array.

public getAll() : array<string|int, T>
Return values
array<string|int, T>

getIterator()

Retrieves an iterator to traverse this object.

public getIterator() : ArrayIterator<string|int, T>
Attributes
#[ReturnTypeWillChange]
Return values
ArrayIterator<string|int, T>

merge()

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

public merge(Collection<string|int, T$collection) : Collection<string|int, T>
Parameters
$collection : Collection<string|int, T>
Return values
Collection<string|int, T>

offsetExists()

Checks whether an item in this collection exists.

public offsetExists(string|int $offset) : bool
Parameters
$offset : string|int

The index to check on.

Attributes
#[ReturnTypeWillChange]
Return values
bool

offsetGet()

Retrieves an item from the collection with the given index.

public offsetGet(string|int $offset) : T|null
Parameters
$offset : string|int

The offset to retrieve.

Attributes
#[ReturnTypeWillChange]
Return values
T|null

offsetSet()

Sets an item at the given index.

public offsetSet((array-key)|null $offset, T $value) : void
Parameters
$offset : (array-key)|null

The offset to assign the value to.

$value : T

The value to set.

Tags
throws
InvalidArgumentException

If the key is null or an empty string.

Attributes
#[ReturnTypeWillChange]

offsetUnset()

Removes an item with the given index from the collection.

public offsetUnset(string|int $offset) : void
Parameters
$offset : string|int

The offset to unset.

Attributes
#[ReturnTypeWillChange]

set()

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

public set(string|int $index, T $item) : void
Parameters
$index : string|int

An index value to recognize this item with.

$item : T

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


        
On this page

Search results