1 | <?php |
||
21 | class RecordIterator implements \Iterator, \Countable, \JsonSerializable |
||
22 | { |
||
23 | /** |
||
24 | * Current iterator position. |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | private $position = 0; |
||
29 | |||
30 | /** |
||
31 | * Set of "methods" to be decorated. |
||
32 | * |
||
33 | * @var callable[] |
||
34 | */ |
||
35 | private $callbacks = []; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $class = ''; |
||
41 | |||
42 | /** |
||
43 | * Indication that entity cache must be used. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $cache = true; |
||
48 | |||
49 | /** |
||
50 | * Data to be iterated. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $data = []; |
||
55 | |||
56 | /** |
||
57 | * Constructed record instances. Cache. |
||
58 | * |
||
59 | * @var RecordEntity[] |
||
60 | */ |
||
61 | protected $instances = []; |
||
62 | |||
63 | /** |
||
64 | * @invisible |
||
65 | * @var ORM |
||
66 | */ |
||
67 | protected $orm = null; |
||
68 | |||
69 | /** |
||
70 | * @param ORM $orm |
||
71 | * @param string $class |
||
72 | * @param array $data |
||
73 | * @param bool $cache |
||
74 | * @param callable[] $callbacks |
||
75 | */ |
||
76 | public function __construct(ORM $orm, $class, array $data, $cache = true, array $callbacks = []) |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function count() |
||
95 | |||
96 | /** |
||
97 | * Get all Records as array. |
||
98 | * |
||
99 | * @return RecordInterface[] |
||
100 | */ |
||
101 | public function all() |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | * |
||
122 | * @return RecordInterface |
||
123 | * @see ORM::record() |
||
124 | * @see Record::setContext() |
||
125 | * @throws ORMException |
||
126 | */ |
||
127 | public function current() |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function next() |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | public function key() |
||
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | public function valid() |
||
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | public function rewind() |
||
174 | |||
175 | /** |
||
176 | * Check if record or record with specified id presents in iteration. |
||
177 | * |
||
178 | * @param RecordEntity|string|int $record |
||
179 | * @return true |
||
180 | */ |
||
181 | public function has($record) |
||
218 | |||
219 | /** |
||
220 | * Executes decorated method providing itself as function argument. |
||
221 | * |
||
222 | * @param string $method |
||
223 | * @param array $arguments |
||
224 | * @return mixed |
||
225 | * @throws IteratorException |
||
226 | */ |
||
227 | public function __call($method, array $arguments) |
||
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function jsonSerialize() |
||
243 | |||
244 | /** |
||
245 | * @return RecordEntity[] |
||
246 | */ |
||
247 | public function __debugInfo() |
||
251 | |||
252 | /** |
||
253 | * Flushing references. |
||
254 | */ |
||
255 | public function __destruct() |
||
261 | } |