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 $
26
* @see Zend_Service_Amazon_Item
28
require_once 'Zend/Service/Amazon/Item.php';
33
* @package Zend_Service
35
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
36
* @license http://framework.zend.com/license/new-bsd New BSD License
38
class Zend_Service_Amazon_ResultSet implements SeekableIterator
41
* A DOMNodeList of <Item> elements
45
protected $_results = null;
48
* Amazon Web Service Return Document
55
* XPath Object for $this->_dom
62
* Current index for SeekableIterator
66
protected $_currentIndex = 0;
69
* Create an instance of Zend_Service_Amazon_ResultSet and create the necessary data objects
71
* @param DOMDocument $dom
74
public function __construct(DOMDocument $dom)
77
$this->_xpath = new DOMXPath($dom);
78
$this->_xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
79
$this->_results = $this->_xpath->query('//az:Item');
83
* Total Number of results returned
85
* @return int Total number of results returned
87
public function totalResults()
89
$result = $this->_xpath->query('//az:TotalResults/text()');
90
return (int) $result->item(0)->data;
94
* Total Number of pages returned
96
* @return int Total number of pages returned
98
public function totalPages()
100
$result = $this->_xpath->query('//az:TotalPages/text()');
101
return (int) $result->item(0)->data;
105
* Implement SeekableIterator::current()
107
* @return Zend_Service_Amazon_Item
109
public function current()
111
return new Zend_Service_Amazon_Item($this->_results->item($this->_currentIndex));
115
* Implement SeekableIterator::key()
119
public function key()
121
return $this->_currentIndex;
125
* Implement SeekableIterator::next()
129
public function next()
131
$this->_currentIndex += 1;
135
* Implement SeekableIterator::rewind()
139
public function rewind()
141
$this->_currentIndex = 0;
145
* Implement SeekableIterator::seek()
148
* @throws OutOfBoundsException
151
public function seek($index)
153
$indexInt = (int) $index;
154
if ($indexInt >= 0 && (null === $this->_results || $indexInt < $this->_results->length)) {
155
$this->_currentIndex = $indexInt;
157
throw new OutOfBoundsException("Illegal index '$index'");
162
* Implement SeekableIterator::valid()
166
public function valid()
168
return null !== $this->_results && $this->_currentIndex < $this->_results->length;