Abstract.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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-2015 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. * @category Zend
  24. * @package Zend_Service
  25. * @subpackage Ebay
  26. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. abstract class Zend_Service_Ebay_Finding_Set_Abstract implements SeekableIterator, Countable
  30. {
  31. /**
  32. * @var DOMNodeList
  33. */
  34. protected $_nodes;
  35. /**
  36. * @var integer
  37. */
  38. protected $_key = 0;
  39. /**
  40. * @param DOMNodeList $nodes
  41. * @return void
  42. */
  43. public function __construct(DOMNodeList $nodes)
  44. {
  45. $this->_nodes = $nodes;
  46. $this->_init();
  47. }
  48. /**
  49. * Initialize object.
  50. *
  51. * Called from {@link __construct()} as final step of object initialization.
  52. *
  53. * @return void
  54. */
  55. protected function _init()
  56. {
  57. }
  58. /**
  59. * Implement SeekableIterator::seek()
  60. *
  61. * @param integer $key
  62. * @throws OutOfBoundsException When $key is not seekable
  63. * @return void
  64. */
  65. public function seek($key)
  66. {
  67. if ($key < 0 || $key >= $this->count()) {
  68. $message = "Position '{$key}' is not seekable.";
  69. throw new OutOfBoundsException($message);
  70. }
  71. $this->_key = $key;
  72. }
  73. /**
  74. * Implement Iterator::key()
  75. *
  76. * @return integer
  77. */
  78. public function key()
  79. {
  80. return $this->_key;
  81. }
  82. /**
  83. * Implement Iterator::next()
  84. *
  85. * @return void
  86. */
  87. public function next()
  88. {
  89. $this->_key++;
  90. }
  91. /**
  92. * Implement Iterator::rewind()
  93. *
  94. * @return void
  95. */
  96. public function rewind()
  97. {
  98. $this->_key = 0;
  99. }
  100. /**
  101. * Implement Iterator::valid()
  102. *
  103. * @return boolean
  104. */
  105. public function valid()
  106. {
  107. return $this->_key >= 0 && $this->_key < $this->count();
  108. }
  109. /**
  110. * Implement Countable::current()
  111. *
  112. * @return integer
  113. */
  114. public function count()
  115. {
  116. return $this->_nodes ? $this->_nodes->length : 0;
  117. }
  118. }