MultiBulkResponse.php 965 B

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