-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathGroupByObjectIterator.php
More file actions
45 lines (41 loc) · 957 Bytes
/
GroupByObjectIterator.php
File metadata and controls
45 lines (41 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* This file is part of TwigLambda
*
* (c) Damian Polac <damian.polac.111@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DPolac\TwigLambda;
/**
* Behave like ArrayIterator over $array, but returns
* objects from $keys array as keys.
*
* @internal
*/
final class GroupByObjectIterator implements \Iterator
{
private $array;
private $keys;
public function __construct(array $array, array $keys)
{
$this->array = $array;
$this->keys = $keys;
}
function rewind() {
return reset($this->array);
}
function current() {
return current($this->array);
}
function key() {
return $this->keys[key($this->array)];
}
function next() {
return next($this->array);
}
function valid() {
return key($this->array) !== null;
}
}