*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Service / Amazon / ResultSet.php
blob5a467d1626368cb04788ba4f4289bc678842ec64
1 <?php
3 /**
4 * Zend Framework
6 * LICENSE
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.
16 * @category Zend
17 * @package Zend_Service
18 * @subpackage Amazon
19 * @copyright Copyright (c) 2005-2009 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 16211 2009-06-21 19:23:55Z thomas $
25 /**
26 * @see Zend_Service_Amazon_Item
28 require_once 'Zend/Service/Amazon/Item.php';
31 /**
32 * @category Zend
33 * @package Zend_Service
34 * @subpackage Amazon
35 * @copyright Copyright (c) 2005-2009 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
40 /**
41 * A DOMNodeList of <Item> elements
43 * @var DOMNodeList
45 protected $_results = null;
47 /**
48 * Amazon Web Service Return Document
50 * @var DOMDocument
52 protected $_dom;
54 /**
55 * XPath Object for $this->_dom
57 * @var DOMXPath
59 protected $_xpath;
61 /**
62 * Current index for SeekableIterator
64 * @var int
66 protected $_currentIndex = 0;
68 /**
69 * Create an instance of Zend_Service_Amazon_ResultSet and create the necessary data objects
71 * @param DOMDocument $dom
72 * @return void
74 public function __construct(DOMDocument $dom)
76 $this->_dom = $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');
82 /**
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;
93 /**
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()
117 * @return int
119 public function key()
121 return $this->_currentIndex;
125 * Implement SeekableIterator::next()
127 * @return void
129 public function next()
131 $this->_currentIndex += 1;
135 * Implement SeekableIterator::rewind()
137 * @return void
139 public function rewind()
141 $this->_currentIndex = 0;
145 * Implement SeekableIterator::seek()
147 * @param int $index
148 * @throws OutOfBoundsException
149 * @return void
151 public function seek($index)
153 $indexInt = (int) $index;
154 if ($indexInt >= 0 && (null === $this->_results || $indexInt < $this->_results->length)) {
155 $this->_currentIndex = $indexInt;
156 } else {
157 throw new OutOfBoundsException("Illegal index '$index'");
162 * Implement SeekableIterator::valid()
164 * @return boolean
166 public function valid()
168 return null !== $this->_results && $this->_currentIndex < $this->_results->length;