MultiBulkResponseTuple.php 970 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. class MultiBulkResponseTuple extends MultiBulkResponse
  12. {
  13. private $_iterator;
  14. public function __construct(MultiBulkResponseSimple $iterator)
  15. {
  16. $virtualSize = count($iterator) / 2;
  17. $this->_iterator = $iterator;
  18. $this->_position = 0;
  19. $this->_current = $virtualSize > 0 ? $this->getValue() : null;
  20. $this->_replySize = $virtualSize;
  21. }
  22. public function __destruct()
  23. {
  24. $this->_iterator->sync();
  25. }
  26. protected function getValue()
  27. {
  28. $k = $this->_iterator->current();
  29. $this->_iterator->next();
  30. $v = $this->_iterator->current();
  31. $this->_iterator->next();
  32. return array($k, $v);
  33. }
  34. }