|
17 | 17 | * Filtered table representation. |
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. |
@@ -948,43 +945,18 @@ public function getReferencingTable( |
948 | 945 | } |
949 | 946 |
|
950 | 947 |
|
951 | | - /********************* interface Iterator ****************d*g**/ |
| 948 | + /********************* interface IteratorAggregate ****************d*g**/ |
952 | 949 |
|
953 | 950 |
|
954 | | - public function rewind(): void |
| 951 | + /** @return \Generator<T> */ |
| 952 | + public function getIterator(): \Generator |
955 | 953 | { |
956 | 954 | $this->execute(); |
957 | | - $this->keys = array_keys($this->data); |
958 | | - reset($this->keys); |
959 | | - } |
960 | | - |
961 | | - |
962 | | - /** @return T|false */ |
963 | | - public function current(): ActiveRow|false |
964 | | - { |
965 | | - return ($key = current($this->keys)) !== false |
966 | | - ? $this->data[$key] |
967 | | - : false; |
968 | | - } |
969 | | - |
970 | | - |
971 | | - public function key(): string|int |
972 | | - { |
973 | | - return current($this->keys); |
974 | | - } |
975 | | - |
976 | | - |
977 | | - public function next(): void |
978 | | - { |
979 | | - do { |
980 | | - next($this->keys); |
981 | | - } while (($key = current($this->keys)) !== false && !isset($this->data[$key])); |
982 | | - } |
983 | | - |
984 | | - |
985 | | - public function valid(): bool |
986 | | - { |
987 | | - return current($this->keys) !== false; |
| 955 | + foreach ($this->data as $key => $value) { |
| 956 | + if (isset($this->data[$key])) { // may be unset by offsetUnset |
| 957 | + yield $key => $value; |
| 958 | + } |
| 959 | + } |
988 | 960 | } |
989 | 961 |
|
990 | 962 |
|
|
0 commit comments