Elgg  Version 2.3
InMemory.php
Go to the documentation of this file.
1 <?php
3 
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 }
static fromArray(array $items)
Factory function for converting from an array to a ton of items.
Definition: InMemory.php:90
if(!$items) $item
Definition: delete.php:17
Uses native PHP array to implement the Collection interface.
Definition: InMemory.php:13
filter(callable $filter)
Definition: InMemory.php:42
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
A read-only interface to a (possibly mutable) group of items.
Definition: Collection.php:33
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5