/** * Set the data source for the result set * * @param Iterator|IteratorAggregate|ResultInterface $dataSource * @return ResultSet * @throws Exception\InvalidArgumentException */ public function initialize($dataSource) { if ($dataSource instanceof ResultInterface) { $this->count = $dataSource->count(); $this->fieldCount = $dataSource->getFieldCount(); $this->dataSource = $dataSource; return $this; } if (is_array($dataSource)) { // its safe to get numbers from an array $first = current($dataSource); reset($dataSource); $this->count = count($dataSource); $this->fieldCount = count($first); $this->dataSource = new ArrayIterator($dataSource); } elseif ($dataSource instanceof IteratorAggregate) { $this->dataSource = $dataSource->getIterator(); } elseif ($dataSource instanceof Iterator) { $this->dataSource = $dataSource; } else { throw new Exception\InvalidArgumentException('DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate'); } if ($this->count == null && $this->dataSource instanceof Countable) { $this->count = $this->dataSource->count(); } return $this; }
/** * Iterator: rewind * * @return void */ public function rewind() { if (!is_array($this->buffer)) { if ($this->dataSource instanceof Iterator) { $this->dataSource->rewind(); } else { reset($this->dataSource); } } $this->position = 0; }
/** * @covers SphinxSearch\Search::showStatus * @covers SphinxSearch\Search::show */ public function testShowStatus() { $mockShow = $this->mockSql->show(); $mockShow->expects($this->once())->method('show')->with($this->equalTo(Show::SHOW_STATUS)); $mockShow->expects($this->once())->method('like')->with($this->equalTo('up%')); // Assumes prepared statement $this->mockResult->expects($this->at(0))->method('rewind')->will($this->returnValue(true)); $this->mockResult->expects($this->at(1))->method('valid')->will($this->returnValue(true)); $this->mockResult->expects($this->at(2))->method('current')->will($this->returnValue(['Counter' => 'uptime', 'Value' => '1392'])); $this->mockResult->expects($this->at(3))->method('next'); $this->mockResult->expects($this->at(4))->method('valid')->will($this->returnValue(false)); $result = $this->search->showStatus('up%'); $this->assertInternalType('array', $result); $this->assertCount(1, $result); $this->assertArrayHasKey('uptime', $result); $this->assertEquals('1392', $result['uptime']); }
/** * Checks if current position is valid * * @link http://php.net/manual/en/iterator.valid.php * @return bool */ public function valid() { return $this->queryResult && $this->queryResult->getAffectedRows() && $this->currentSiteInfo instanceof SiteInfo; }
/** * @return bool */ function valid() { return $this->_result->valid(); }