|
17 | 17 | * Represents filtered table result. |
18 | 18 | * Selection is based on the great library NotORM http://www.notorm.com written by Jakub Vrana. |
19 | 19 | * @template T of ActiveRow |
20 | | - * @implements \Iterator<T> |
| 20 | + * @implements \IteratorAggregate<T> |
21 | 21 | * @implements \ArrayAccess<T> |
22 | 22 | */ |
23 | | -class Selection implements \Iterator, \ArrayAccess, \Countable |
| 23 | +class Selection implements \IteratorAggregate, \ArrayAccess, \Countable |
24 | 24 | { |
25 | 25 | protected readonly Explorer $explorer; |
26 | 26 | protected readonly ?Nette\Caching\Cache $cache; |
@@ -58,9 +58,6 @@ class Selection implements \Iterator, \ArrayAccess, \Countable |
58 | 58 | /** should instance observe accessed columns caching */ |
59 | 59 | protected ?self $observeCache = null; |
60 | 60 |
|
61 | | - /** of primary key values */ |
62 | | - protected array $keys = []; |
63 | | - |
64 | 61 |
|
65 | 62 | /** |
66 | 63 | * Creates filtered table representation. |
@@ -953,43 +950,18 @@ public function getReferencingTable( |
953 | 950 | } |
954 | 951 |
|
955 | 952 |
|
956 | | - /********************* interface Iterator ****************d*g**/ |
| 953 | + /********************* interface IteratorAggregate ****************d*g**/ |
957 | 954 |
|
958 | 955 |
|
959 | | - public function rewind(): void |
| 956 | + /** @return \Generator<T> */ |
| 957 | + public function getIterator(): \Generator |
960 | 958 | { |
961 | 959 | $this->execute(); |
962 | | - $this->keys = array_keys($this->data); |
963 | | - reset($this->keys); |
964 | | - } |
965 | | - |
966 | | - |
967 | | - /** @return T|false */ |
968 | | - public function current(): ActiveRow|false |
969 | | - { |
970 | | - return ($key = current($this->keys)) !== false |
971 | | - ? $this->data[$key] |
972 | | - : false; |
973 | | - } |
974 | | - |
975 | | - |
976 | | - public function key(): string|int |
977 | | - { |
978 | | - return current($this->keys); |
979 | | - } |
980 | | - |
981 | | - |
982 | | - public function next(): void |
983 | | - { |
984 | | - do { |
985 | | - next($this->keys); |
986 | | - } while (($key = current($this->keys)) !== false && !isset($this->data[$key])); |
987 | | - } |
988 | | - |
989 | | - |
990 | | - public function valid(): bool |
991 | | - { |
992 | | - return current($this->keys) !== false; |
| 960 | + foreach ($this->data as $key => $value) { |
| 961 | + if (isset($this->data[$key])) { // may be unset by offsetUnset |
| 962 | + yield $key => $value; |
| 963 | + } |
| 964 | + } |
993 | 965 | } |
994 | 966 |
|
995 | 967 |
|
|
0 commit comments