8
* This source file is subject to the new BSD license that is bundled
9
* with this package in the file LICENSE.txt.
10
* It is also available through the world-wide-web at this URL:
11
* http://framework.zend.com/license/new-bsd
12
* If you did not receive a copy of the license and are unable to
13
* obtain it through the world-wide-web, please send an email
14
* to license@zend.com so we can send you a copy immediately.
17
* @package Zend_Service
19
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
20
* @license http://framework.zend.com/license/new-bsd New BSD License
21
* @version $Id: ResultSet.php 8064 2008-02-16 10:58:39Z thomas $
27
* @package Zend_Service
29
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
30
* @license http://framework.zend.com/license/new-bsd New BSD License
32
class Zend_Service_Yahoo_ResultSet implements SeekableIterator
35
* Total number of results available
39
public $totalResultsAvailable;
42
* The number of results in this result set
46
public $totalResultsReturned;
49
* The offset in the total result set of this search set
53
public $firstResultPosition;
56
* A DOMNodeList of results
63
* Yahoo Web Service Return Document
70
* Xpath Object for $this->_dom
77
* Current Index for SeekableIterator
81
protected $_currentIndex = 0;
85
* Parse the search response and retrieve the results for iteration
87
* @param DOMDocument $dom the REST fragment for this object
90
public function __construct(DOMDocument $dom)
92
$this->totalResultsAvailable = (int) $dom->documentElement->getAttribute('totalResultsAvailable');
93
$this->totalResultsReturned = (int) $dom->documentElement->getAttribute('totalResultsReturned');
94
$this->firstResultPosition = (int) $dom->documentElement->getAttribute('firstResultPosition');
97
$this->_xpath = new DOMXPath($dom);
99
$this->_xpath->registerNamespace('yh', $this->_namespace);
101
$this->_results = $this->_xpath->query('//yh:Result');
106
* Total Number of results returned
108
* @return int Total number of results returned
110
public function totalResults()
112
return $this->totalResultsReturned;
117
* Implement SeekableIterator::current()
119
* Must be implemented by child classes
121
* @throws Zend_Service_Exception
122
* @return Zend_Service_Yahoo_Result
124
public function current()
127
* @see Zend_Service_Exception
129
require_once 'Zend/Service/Exception.php';
130
throw new Zend_Service_Exception('Zend_Service_Yahoo_ResultSet::current() must be implemented by child '
136
* Implement SeekableIterator::key()
140
public function key()
142
return $this->_currentIndex;
147
* Implement SeekableIterator::next()
151
public function next()
153
$this->_currentIndex += 1;
158
* Implement SeekableIterator::rewind()
162
public function rewind()
164
$this->_currentIndex = 0;
169
* Implement SeekableIterator::seek()
173
* @throws OutOfBoundsException
175
public function seek($index)
177
$indexInt = (int) $index;
178
if ($indexInt >= 0 && $indexInt < $this->_results->length) {
179
$this->_currentIndex = $indexInt;
181
throw new OutOfBoundsException("Illegal index '$index'");
187
* Implement SeekableIterator::valid()
191
public function valid()
193
return $this->_currentIndex < $this->_results->length;