Predis\Protocol\Text\Handler\BulkResponse::handle PHP Метод

handle() публичный Метод

public handle ( Predis\Connection\CompositeConnectionInterface $connection, $payload )
$connection Predis\Connection\CompositeConnectionInterface
    public function handle(CompositeConnectionInterface $connection, $payload)
    {
        $length = (int) $payload;
        if ("{$length}" !== $payload) {
            CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length for a bulk response [{$connection->getParameters()}]"));
        }
        if ($length >= 0) {
            return substr($connection->readBuffer($length + 2), 0, -2);
        }
        if ($length == -1) {
            return;
        }
        CommunicationException::handle(new ProtocolException($connection, "Value '{$payload}' is not a valid length for a bulk response [{$connection->getParameters()}]"));
        return;
    }

Usage Example

 /**
  * @group disconnected
  * @expectedException \Predis\Protocol\ProtocolException
  * @expectedExceptionMessage Cannot parse 'invalid' as a valid length for a bulk response.
  */
 public function testInvalidLength()
 {
     $handler = new Handler\BulkResponse();
     $connection = $this->getMock('Predis\\Connection\\CompositeConnectionInterface');
     $connection->expects($this->never())->method('readLine');
     $connection->expects($this->never())->method('readBuffer');
     $handler->handle($connection, 'invalid');
 }
BulkResponse