mirror of
https://github.com/predis/predis.git
synced 2026-08-24 15:39:28 +00:00
59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Predis\Iterators;
|
|
|
|
abstract class MultiBulkResponse implements \Iterator, \Countable
|
|
{
|
|
protected $_position;
|
|
protected $_current;
|
|
protected $_replySize;
|
|
|
|
public function rewind()
|
|
{
|
|
// NOOP
|
|
}
|
|
|
|
public function current()
|
|
{
|
|
return $this->_current;
|
|
}
|
|
|
|
public function key()
|
|
{
|
|
return $this->_position;
|
|
}
|
|
|
|
public function next()
|
|
{
|
|
if (++$this->_position < $this->_replySize) {
|
|
$this->_current = $this->getValue();
|
|
}
|
|
|
|
return $this->_position;
|
|
}
|
|
|
|
public function valid()
|
|
{
|
|
return $this->_position < $this->_replySize;
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
// Use count if you want to get the size of the current multi-bulk
|
|
// response without using iterator_count (which actually consumes our
|
|
// iterator to calculate the size, and we cannot perform a rewind)
|
|
return $this->_replySize;
|
|
}
|
|
|
|
protected abstract function getValue();
|
|
}
|