import poc
[m6w6/pq-gateway] / lib / pq / Gateway / Rowset.php
1 <?php
2
3 namespace pq\Gateway;
4
5 class Rowset implements \IteratorAggregate
6 {
7 /**
8 * @var \pq\Gateway\Table
9 */
10 protected $table;
11
12 /**
13 * @var array
14 */
15 protected $rows;
16
17 /**
18 * @param \pq\Gateway\Table $table
19 * @param \pq\Result $result
20 */
21 function __construct(Table $table, \pq\Result $result, $rowClass = "\\pq\\Gateway\\Row") {
22 $this->table = $table;
23 while (($row = $result->fetchRow(\pq\Result::FETCH_ASSOC))) {
24 $this->rows[] = new $rowClass($this->table, $row);
25 }
26 }
27
28 /**
29 * @implements \IteratorAggregate
30 * @return \pq\Gateway\ArrayIterator
31 */
32 function getIterator() {
33 return new \ArrayIterator($this->rows);
34 }
35
36 /**
37 * Filter by callback
38 * @param callable $cb
39 * @return \pq\Gateway\Rowset
40 */
41 function filter(callable $cb) {
42 $rowset = clone $this;
43 $rowset->rows = array_filter($this->rows, $cb);
44 return $rowset;
45 }
46 }