CollectionInterface extends BaseInterface, Countable, IteratorAggregate, ArrayAccess
Collection interface.
Table of Contents
Methods
- add() : self
- Add an item or throw an exception if exists.
- count() : int
- Implements Countable.
- filter() : self
- Filters items using a callback function.
- first() : ItemInterface|null
- Retrieves the first item.
- get() : ItemInterface
- Retrieves an item or throw an exception if not exists.
- getId() : string
- Returns the collection's identifier.
- getIterator() : ArrayIterator
- Implements \IteratorAggregate.
- getPosition() : int
- Retrieves an item position or throw an exception if not exists.
- has() : bool
- Does the item $id exists?
- keys() : array<string|int, mixed>
- Retrieves all keys.
- map() : self
- Applies a callback to items.
- remove() : self
- Removes an item or throw an exception if not exists.
- replace() : self
- Replaces an item or throw an exception if not exists.
- reverse() : self
- Reverse items order.
- setId() : BaseInterface
- Set the collection's identifier.
- toArray() : array<string|int, mixed>
- Returns collection as array.
- toJson() : string
- Returns a JSON string of items.
- usort() : self
- Implements usort.
Methods
add()
Add an item or throw an exception if exists.
public
add(ItemInterface $item) : self
Parameters
- $item : ItemInterface
Return values
selfcount()
Implements Countable.
public
count() : int
Return values
intfilter()
Filters items using a callback function.
public
filter(Closure $callback) : self
Parameters
- $callback : Closure
Return values
selffirst()
Retrieves the first item.
public
first() : ItemInterface|null
Return values
ItemInterface|nullget()
Retrieves an item or throw an exception if not exists.
public
get(string $id) : ItemInterface
Parameters
- $id : string
Return values
ItemInterfacegetId()
Returns the collection's identifier.
public
getId() : string
Return values
stringgetIterator()
Implements \IteratorAggregate.
public
getIterator() : ArrayIterator
Return values
ArrayIteratorgetPosition()
Retrieves an item position or throw an exception if not exists.
public
getPosition(string $id) : int
Parameters
- $id : string
Return values
inthas()
Does the item $id exists?
public
has(string $id) : bool
Parameters
- $id : string
Return values
boolkeys()
Retrieves all keys.
public
keys() : array<string|int, mixed>
Return values
array<string|int, mixed>map()
Applies a callback to items.
public
map(Closure $callback) : self
Parameters
- $callback : Closure
Return values
selfremove()
Removes an item or throw an exception if not exists.
public
remove(string $id) : self
Parameters
- $id : string
Return values
selfreplace()
Replaces an item or throw an exception if not exists.
public
replace(string $id, ItemInterface $item) : self
Parameters
- $id : string
- $item : ItemInterface
Return values
selfreverse()
Reverse items order.
public
reverse() : self
Return values
selfsetId()
Set the collection's identifier.
public
setId(string $id) : BaseInterface
Parameters
- $id : string
Return values
BaseInterfacetoArray()
Returns collection as array.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>toJson()
Returns a JSON string of items.
public
toJson() : string
Return values
stringusort()
Implements usort.
public
usort([Closure|null $callback = null ]) : self
Parameters
- $callback : Closure|null = null