* @param \pq\Result $result
* @return \pq\Gateway\Rowset
*/
- function __invoke(\pq\Result $result) {
+ function __invoke(\pq\Result $result = null) {
$that = clone $this;
$that->hydrate($result);
return $that;
$this->rows = array();
if ($result) {
- $row = $this->row;
+ $row = $this->getRowPrototype();
if (is_callable($row)) {
while (($data = $result->fetchRow(\pq\Result::FETCH_ASSOC))) {
return $this;
}
+ /**
+ * Get the row prototype
+ * @return mixed
+ */
+ function getRowPrototype() {
+ return $this->row;
+ }
+
/**
* @return \pq\Gateway\Table
*/
function rewind() {
$this->index = 0;
}
+
/**
* @implements \Iterator
*/
function next() {
++$this->index;
}
+
/**
* @implements \Iterator
* @return bool
function valid() {
return $this->index < count($this->rows);
}
+
/**
* @implements \Iterator
* @return \pq\Gateway\Row
*/
function current() {
+ if (!$this->valid()) {
+ throw new \OutOfBoundsException("Invalid row index {$this->index}");
+ }
return $this->rows[$this->index];
}
+
/**
* @implements \Iterator
* @return int
*/
function filter(callable $cb) {
$rowset = clone $this;
+ $rowset->index = 0;
$rowset->rows = array_filter($this->rows, $cb);
return $rowset;
}