MultiBulkResponse.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Iterators;
  11. abstract class MultiBulkResponse implements \Iterator, \Countable
  12. {
  13. protected $_position;
  14. protected $_current;
  15. protected $_replySize;
  16. public function rewind()
  17. {
  18. // NOOP
  19. }
  20. public function current()
  21. {
  22. return $this->_current;
  23. }
  24. public function key()
  25. {
  26. return $this->_position;
  27. }
  28. public function next()
  29. {
  30. if (++$this->_position < $this->_replySize) {
  31. $this->_current = $this->getValue();
  32. }
  33. return $this->_position;
  34. }
  35. public function valid()
  36. {
  37. return $this->_position < $this->_replySize;
  38. }
  39. public function count()
  40. {
  41. // Use count if you want to get the size of the current multi-bulk
  42. // response without using iterator_count (which actually consumes our
  43. // iterator to calculate the size, and we cannot perform a rewind)
  44. return $this->_replySize;
  45. }
  46. protected abstract function getValue();
  47. }