Elgg  Version 1.11
ArrayCollection.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Structs;
3 
4 use Exception;
5 
15 final class ArrayCollection implements Collection {
17  private $items;
18 
24  public function __construct(array $items = array()) {
25  $this->items = $items;
26  }
27 
29  public function contains($item) {
30  return in_array($item, $this->items, true);
31  }
32 
34  public function count() {
35  return count($this->items);
36  }
37 
39  public function current() {
40  return current($this->items);
41  }
42 
44  public function filter(callable $filter) {
45  $results = array();
46 
47  foreach ($this->items as $item) {
48  if ($filter($item)) {
49  $results[] = $item;
50  }
51  }
52 
53  return new ArrayCollection($results);
54  }
55 
57  public function key() {
58  return key($this->items);
59  }
60 
62  public function map(callable $mapper) {
63  $results = array();
64  foreach ($this->items as $item) {
65  $results[] = $mapper($item);
66  }
67  return new ArrayCollection($results);
68  }
69 
71  public function next() {
72  return next($this->items);
73  }
74 
76  public function rewind() {
77  reset($this->items);
78  }
79 
81  public function valid() {
82  return key($this->items) !== NULL;
83  }
84 }
$item
Definition: item.php:12
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
__construct(array $items=array())
Constructor.