44 if (!is_subclass_of(
$item_class, CollectionItemInterface::class)) {
65 $class = $this->item_class ? : CollectionItemInterface::class;
75 public function all() {
82 #[\ReturnTypeWillChange] 84 return count($this->items);
101 public function get(
$id) {
109 return array_key_exists(
$id, $this->items);
115 public function remove(
$id) {
116 unset($this->items[
$id]);
145 public function filter(callable $callback = null) {
147 $items = array_filter($this->items, $callback);
149 $items = array_values($this->items);
158 public function sort(callable $callback = null) {
162 $p2 = $f2->getPriority() ? : 500;
167 return $p1 < $p2 ? -1 : 1;
171 uasort($this->items, $callback);
189 public function walk(callable $callback) {
190 foreach ($this->items as
$id =>
$item) {
191 call_user_func($callback,
$item,
$id);
200 public function map(callable $callback) {
218 #[\ReturnTypeWillChange] 226 #[\ReturnTypeWillChange] 234 #[\ReturnTypeWillChange] 245 #[\ReturnTypeWillChange] 247 if (isset($this->items[
$offset]) && isset($this->position)) {
252 unset($this->items[$offset]);
262 #[\ReturnTypeWillChange] 264 $keys = array_keys($this->items);
272 #[\ReturnTypeWillChange] 280 #[\ReturnTypeWillChange] 282 $keys = array_keys($this->items);
290 #[\ReturnTypeWillChange] 292 $keys = array_keys($this->items);
294 return isset(
$keys[$this->position]);
300 #[\ReturnTypeWillChange] 308 #[\ReturnTypeWillChange] 310 $keys = array_keys($this->items);
offsetSet($offset, $value)
{}
A collection of unique items.
Exception thrown if an argument is not of the expected type.
getPriority()
Get priority (weight) of the item within a collection.
has($id)
{Check if collection has an item with a given ID.IDbool}
Collection item interface.
assertValidItem($item)
Validate if item is a valid collection item.
map(callable $callback)
{Walk through all items in the collection and apply a callback.Mappermixed}
Exception thrown if a value is not a valid key.
walk(callable $callback)
Walk through members of the collection and apply a callback.
current()
SeekableIterator interface functions.
__construct($items=[], $item_class=null)
Constructor.
count()
{Count collection items.int}
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
An interface for organizing items into collections.
add($item)
{Add a new item to collection.Itemstatic}
fill($items)
{Replace collection items.$items Itemsstatic}
all()
{Returns all collection items by reference.CollectionItemInterface[]}
filter(callable $callback=null)
{Filter collection items using a custom filter Returns a new collection instance.Filterstatic} ...
sort(callable $callback=null)
{Sort fields using custom callable If not provided, will sort items by priority.Sorterstatic} ...
$id
Generic annotation delete action.
offsetExists($offset)
ArrayAccess interface functions.
merge($items)
{Add new items to collection, replacing items with matching IDs.$items Itemsstatic} ...