Elgg
Version 2.3
engine
classes
Elgg
Structs
Collection
InMemory.php
Go to the documentation of this file.
1
<?php
2
namespace
Elgg\Structs\Collection
;
3
4
use
Elgg\Structs\Collection
;
5
13
final
class
InMemory
implements
Collection
{
15
private
$items;
16
22
private
function
__construct(array $items = array()) {
23
$this->items = $items;
24
}
25
27
public
function
contains
(
$item
) {
28
return
in_array(
$item
, $this->items,
true
);
29
}
30
32
public
function
count
() {
33
return
count
($this->items);
34
}
35
37
public
function
current
() {
38
return
current
($this->items);
39
}
40
42
public
function
filter
(callable
$filter
) {
43
$results = array();
44
45
foreach
($this->items as
$item
) {
46
if
(
$filter
(
$item
)) {
47
$results[] =
$item
;
48
}
49
}
50
51
return
new
self
($results);
52
}
53
55
public
function
key
() {
56
return
key
($this->items);
57
}
58
60
public
function
map
(callable $mapper) {
61
$results = array();
62
foreach
($this->items as
$item
) {
63
$results[] = $mapper(
$item
);
64
}
65
return
self::fromArray
($results);
66
}
67
69
public
function
next
() {
70
return
next
($this->items);
71
}
72
74
public
function
rewind
() {
75
reset($this->items);
76
}
77
79
public
function
valid
() {
80
return
key
($this->items) !== NULL;
81
}
82
90
public
static
function
fromArray
(array $items) {
91
return
new
self
(
$items
);
92
}
93
}
Elgg\Structs\Collection\InMemory
Uses native PHP array to implement the Collection interface.
Definition:
InMemory.php:13
Elgg\Structs\Collection\InMemory\rewind
rewind()
@inheritDoc
Definition:
InMemory.php:74
Elgg\Structs\Collection\InMemory\map
map(callable $mapper)
@inheritDoc
Definition:
InMemory.php:60
Elgg\Structs\Collection\InMemory\filter
filter(callable $filter)
@inheritDoc
Definition:
InMemory.php:42
Elgg\Structs\Collection\InMemory\current
current()
@inheritDoc
Definition:
InMemory.php:37
Elgg\Structs\Collection\InMemory\key
key()
@inheritDoc
Definition:
InMemory.php:55
Elgg\Structs\Collection\InMemory\fromArray
static fromArray(array $items)
Factory function for converting from an array to a ton of items.
Definition:
InMemory.php:90
Elgg\Structs\Collection\InMemory\contains
contains($item)
@inheritDoc
Definition:
InMemory.php:27
Elgg\Structs\Collection\InMemory\count
count()
@inheritDoc
Definition:
InMemory.php:32
Elgg\Structs\Collection\InMemory\next
next()
@inheritDoc
Definition:
InMemory.php:69
Elgg\Structs\Collection\InMemory\valid
valid()
@inheritDoc
Definition:
InMemory.php:79
Elgg\Structs\Collection
A read-only interface to a (possibly mutable) group of items.
Definition:
Collection.php:33
Elgg\Structs\Collection
Definition:
InMemory.php:2
$filter
if(! $vars['title'] && $vars['title'] !==false) if(isset($vars['filter_override'])) if(!isset($vars['filter']) &&elgg_is_logged_in() && $context) $filter
Definition:
content.php:62
$item
if(! $items) $item
Definition:
delete.php:17
$items
$items
Definition:
delete.php:11
Generated on Fri Aug 29 2025 00:00:46 for Elgg by
1.9.1