scratch – Blame information for rev 87
?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 ArrayIterator; |
||
16 | use Iterator; |
||
17 | |||
18 | class ExceptIterator implements Iterator |
||
19 | { |
||
20 | private $first; |
||
21 | private $second; |
||
22 | private $result; |
||
23 | |||
24 | public function __construct(Iterator $first, Iterator $second) |
||
25 | { |
||
26 | $this->first = $first; |
||
27 | $this->second = $second; |
||
28 | } |
||
29 | |||
30 | public function current() |
||
31 | { |
||
32 | return $this->result->current(); |
||
33 | } |
||
34 | |||
35 | public function next() |
||
36 | { |
||
37 | $this->result->next(); |
||
38 | } |
||
39 | |||
40 | public function key() |
||
41 | { |
||
42 | return $this->result->key(); |
||
43 | } |
||
44 | |||
45 | public function valid() |
||
46 | { |
||
47 | return $this->result->valid(); |
||
48 | } |
||
49 | |||
50 | public function rewind() |
||
51 | { |
||
52 | if ($this->result === null) { |
||
53 | $this->getResult(); |
||
54 | } |
||
55 | |||
56 | $this->result->rewind(); |
||
57 | } |
||
58 | |||
59 | private function getResult() |
||
60 | { |
||
61 | $firstArray = iterator_to_array($this->first); |
||
62 | $secondArray = iterator_to_array($this->second); |
||
63 | $this->result = new ArrayIterator(array_diff($firstArray, $secondArray)); |
||
64 | } |
||
65 | } |