|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service |
|
17 * @subpackage Ebay |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Abstract.php 20166 2010-01-09 19:00:17Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @category Zend |
|
25 * @package Zend_Service |
|
26 * @subpackage Ebay |
|
27 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
28 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
29 */ |
|
30 abstract class Zend_Service_Ebay_Finding_Set_Abstract implements SeekableIterator, Countable |
|
31 { |
|
32 /** |
|
33 * @var DOMNodeList |
|
34 */ |
|
35 protected $_nodes; |
|
36 |
|
37 /** |
|
38 * @var integer |
|
39 */ |
|
40 protected $_key = 0; |
|
41 |
|
42 /** |
|
43 * @param DOMNodeList $nodes |
|
44 * @return void |
|
45 */ |
|
46 public function __construct(DOMNodeList $nodes) |
|
47 { |
|
48 $this->_nodes = $nodes; |
|
49 $this->_init(); |
|
50 } |
|
51 |
|
52 /** |
|
53 * Initialize object. |
|
54 * |
|
55 * Called from {@link __construct()} as final step of object initialization. |
|
56 * |
|
57 * @return void |
|
58 */ |
|
59 protected function _init() |
|
60 { |
|
61 } |
|
62 |
|
63 /** |
|
64 * Implement SeekableIterator::seek() |
|
65 * |
|
66 * @param integer $key |
|
67 * @throws OutOfBoundsException When $key is not seekable |
|
68 * @return void |
|
69 */ |
|
70 public function seek($key) |
|
71 { |
|
72 if ($key < 0 || $key >= $this->count()) { |
|
73 $message = "Position '{$key}' is not seekable."; |
|
74 throw new OutOfBoundsException($message); |
|
75 } |
|
76 $this->_key = $key; |
|
77 } |
|
78 |
|
79 /** |
|
80 * Implement Iterator::key() |
|
81 * |
|
82 * @return integer |
|
83 */ |
|
84 public function key() |
|
85 { |
|
86 return $this->_key; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Implement Iterator::next() |
|
91 * |
|
92 * @return void |
|
93 */ |
|
94 public function next() |
|
95 { |
|
96 $this->_key++; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Implement Iterator::rewind() |
|
101 * |
|
102 * @return void |
|
103 */ |
|
104 public function rewind() |
|
105 { |
|
106 $this->_key = 0; |
|
107 } |
|
108 |
|
109 /** |
|
110 * Implement Iterator::valid() |
|
111 * |
|
112 * @return boolean |
|
113 */ |
|
114 public function valid() |
|
115 { |
|
116 return $this->_key >= 0 && $this->_key < $this->count(); |
|
117 } |
|
118 |
|
119 /** |
|
120 * Implement Countable::current() |
|
121 * |
|
122 * @return integer |
|
123 */ |
|
124 public function count() |
|
125 { |
|
126 return $this->_nodes ? $this->_nodes->length : 0; |
|
127 } |
|
128 } |