diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Service/Yahoo/ResultSet.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Service/Yahoo/ResultSet.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,195 @@ +_dom + * + * @var DOMXPath + */ + protected $_xpath; + + /** + * Current Index for SeekableIterator + * + * @var int + */ + protected $_currentIndex = 0; + + + /** + * Parse the search response and retrieve the results for iteration + * + * @param DOMDocument $dom the REST fragment for this object + * @return void + */ + public function __construct(DOMDocument $dom) + { + $this->totalResultsAvailable = (int) $dom->documentElement->getAttribute('totalResultsAvailable'); + $this->totalResultsReturned = (int) $dom->documentElement->getAttribute('totalResultsReturned'); + $this->firstResultPosition = (int) $dom->documentElement->getAttribute('firstResultPosition'); + + $this->_dom = $dom; + $this->_xpath = new DOMXPath($dom); + + $this->_xpath->registerNamespace('yh', $this->_namespace); + + $this->_results = $this->_xpath->query('//yh:Result'); + } + + + /** + * Total Number of results returned + * + * @return int Total number of results returned + */ + public function totalResults() + { + return $this->totalResultsReturned; + } + + + /** + * Implement SeekableIterator::current() + * + * Must be implemented by child classes + * + * @throws Zend_Service_Exception + * @return Zend_Service_Yahoo_Result + */ + public function current() + { + /** + * @see Zend_Service_Exception + */ + require_once 'Zend/Service/Exception.php'; + throw new Zend_Service_Exception('Zend_Service_Yahoo_ResultSet::current() must be implemented by child ' + . 'classes'); + } + + + /** + * Implement SeekableIterator::key() + * + * @return int + */ + public function key() + { + return $this->_currentIndex; + } + + + /** + * Implement SeekableIterator::next() + * + * @return void + */ + public function next() + { + $this->_currentIndex += 1; + } + + + /** + * Implement SeekableIterator::rewind() + * + * @return void + */ + public function rewind() + { + $this->_currentIndex = 0; + } + + + /** + * Implement SeekableIterator::seek() + * + * @param int $index + * @return void + * @throws OutOfBoundsException + */ + public function seek($index) + { + $indexInt = (int) $index; + if ($indexInt >= 0 && $indexInt < $this->_results->length) { + $this->_currentIndex = $indexInt; + } else { + throw new OutOfBoundsException("Illegal index '$index'"); + } + } + + + /** + * Implement SeekableIterator::valid() + * + * @return boolean + */ + public function valid() + { + return $this->_currentIndex < $this->_results->length; + } +}