2527b029a1f629cad222161c05e73cf84540a216
5 class Rowset
implements \SeekableIterator
, \Countable
, \JsonSerializable
8 * @var \pq\Gateway\Table
28 * @param \pq\Gateway\Table $table
29 * @param \pq\Result $result
31 function __construct(Table
$table, \pq\Result
$result, $row = "\\pq\\Gateway\\Row") {
32 $this->table
= $table;
35 $this->hydrate($result);
40 * @param \pq\Result $result
41 * @return \pq\Gateway\Rowset
43 function __invoke(\pq\Result
$result) {
45 $that->hydrate($result);
51 * @param \pq\Result $result
54 protected function hydrate(\pq\Result
$result) {
56 $this->rows
= array();
59 if (is_callable($row)) {
60 while (($data = $result->fetchRow(\pq\Result
::FETCH_ASSOC
))) {
61 $this->rows
[] = $row($data);
64 while (($data = $result->fetchRow(\pq\Result
::FETCH_ASSOC
))) {
65 $this->rows
[] = new $row($this->table
, $data);
72 * @return \pq\Gateway\Table
79 array_map(function ($row) {
86 array_map(function ($row) {
93 array_map(function ($row) {
100 * @implements JsonSerilaizable
102 function jsonSerialize() {
103 return array_map(function($row) {
104 return $row->jsonSerialize();
109 * @implements \Iterator
115 * @implements \Iterator
121 * @implements \Iterator
125 return $this->index
< count($this->rows
);
128 * @implements \Iterator
129 * @return \pq\Gateway\Row
132 return $this->rows
[$this->index
];
135 * @implements \Iterator
143 * @implements SeekableIterator
146 function seek($pos) {
147 /* only index for now */
150 if (!$this->valid()) {
151 throw new \
OutOfBoundsException("Invalid seek position ($pos)");
156 * @implements \Countable
160 return count($this->rows
);
164 * Get the rows of this rowset
173 * @param callable $cb
174 * @return \pq\Gateway\Rowset
176 function filter(callable
$cb) {
177 $rowset = clone $this;
178 $rowset->rows
= array_filter($this->rows
, $cb);