MultiBulkResponse.php 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Predis\Iterators;
  3. abstract class MultiBulkResponse implements \Iterator, \Countable
  4. {
  5. protected $_position;
  6. protected $_current;
  7. protected $_replySize;
  8. public function rewind()
  9. {
  10. // NOOP
  11. }
  12. public function current()
  13. {
  14. return $this->_current;
  15. }
  16. public function key()
  17. {
  18. return $this->_position;
  19. }
  20. public function next()
  21. {
  22. if (++$this->_position < $this->_replySize) {
  23. $this->_current = $this->getValue();
  24. }
  25. return $this->_position;
  26. }
  27. public function valid()
  28. {
  29. return $this->_position < $this->_replySize;
  30. }
  31. public function count()
  32. {
  33. // Use count if you want to get the size of the current multi-bulk
  34. // response without using iterator_count (which actually consumes our
  35. // iterator to calculate the size, and we cannot perform a rewind)
  36. return $this->_replySize;
  37. }
  38. protected abstract function getValue();
  39. }