scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of Fusonic-linq. |
||
5 | * https://github.com/fusonic/fusonic-linq |
||
6 | * |
||
7 | * (c) Fusonic GmbH |
||
8 | * |
||
9 | * For the full copyright and license information, please view the LICENSE |
||
10 | * file that was distributed with this source code. |
||
11 | */ |
||
12 | |||
13 | namespace Fusonic\Linq\Iterator; |
||
14 | |||
15 | use Iterator; |
||
16 | use Fusonic\Linq\Helper; |
||
17 | |||
18 | class SelectManyIterator implements Iterator |
||
19 | { |
||
20 | private $iterator; |
||
21 | private $currentIterator; |
||
22 | private $key = 0; |
||
23 | |||
24 | public function __construct(Iterator $iterator) |
||
25 | { |
||
26 | $this->iterator = $iterator; |
||
27 | } |
||
28 | |||
29 | public function current() |
||
30 | { |
||
31 | if ($this->currentIterator != null) { |
||
32 | return $this->currentIterator->current(); |
||
33 | } |
||
34 | |||
35 | return null; |
||
36 | } |
||
37 | |||
38 | public function next() |
||
39 | { |
||
40 | if ($this->currentIterator != null) { |
||
41 | $this->currentIterator->next(); |
||
42 | |||
43 | if (!$this->currentIterator->valid()) { |
||
44 | $this->iterator->next(); |
||
45 | if ($this->iterator->valid()) { |
||
46 | $this->currentIterator = Helper\LinqHelper::getIteratorOrThrow($this->iterator->current()); |
||
47 | if ($this->currentIterator != null) { |
||
48 | $this->currentIterator->rewind(); |
||
49 | $this->key++; |
||
50 | } |
||
51 | } |
||
52 | } else { |
||
53 | $this->key++; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | public function key() |
||
59 | { |
||
60 | return $this->key; |
||
61 | } |
||
62 | |||
63 | public function valid() |
||
64 | { |
||
65 | $current = $this->currentIterator; |
||
66 | return $current != null && $current->valid(); |
||
67 | } |
||
68 | |||
69 | public function rewind() |
||
70 | { |
||
71 | $this->iterator->rewind(); |
||
72 | if ($this->iterator->valid()) { |
||
73 | $current = $this->iterator->current(); |
||
74 | $this->currentIterator = Helper\LinqHelper::getIteratorOrThrow($current); |
||
75 | if ($this->currentIterator != null) { |
||
76 | $this->currentIterator->rewind(); |
||
77 | } |
||
78 | } else { |
||
79 | $this->currentIterator = null; |
||
80 | } |
||
81 | |||
82 | $this->key = 0; |
||
83 | } |
||
84 | } |