MultiBulkResponse.php 993 B

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