Sha256: af0da94ebbcbd714fe7e693aad1db743e6eb08097f8357446140d937a1fd58f8

Contents?: true

Size: 1.19 KB

Versions: 7

Compression:

Stored size: 1.19 KB

Contents

<?php

namespace Predis\Iterators;

use Predis\Network\IConnection;
use Predis\Network\IConnectionSingle;

class MultiBulkResponseSimple extends MultiBulkResponse {
    private $_connection;

    public function __construct(IConnectionSingle $connection, $size) {
        $this->_connection = $connection;
        $this->_position   = 0;
        $this->_current    = $size > 0 ? $this->getValue() : null;
        $this->_replySize  = $size;
    }

    public function __destruct() {
        // When the iterator is garbage-collected (e.g. it goes out of the
        // scope of a foreach) but it has not reached its end, we must sync
        // the client with the queued elements that have not been read from
        // the connection with the server.
        $this->sync();
    }

    public function sync($drop = false) {
        if ($drop == true) {
            if ($this->valid()) {
                $this->_position = $this->_replySize;
                $this->_connection->disconnect();
            }
        }
        else {
            while ($this->valid()) {
                $this->next();
            }
        }
    }

    protected function getValue() {
        return $this->_connection->read();
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appstats-0.25.1 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php
appstats-0.25.0 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php
appstats-0.24.0 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php
appstats-0.23.5 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php
appstats-0.23.4 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php
appstats-0.23.3 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php
appstats-0.23.2 doc/benchmarks/Predis/Iterators/MultiBulkResponseSimple.php