ResponseBulkHandler.php 684 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace Predis\Protocols;
  3. use Predis\Utils;
  4. use Predis\ProtocolException;
  5. use Predis\Network\IConnectionComposable;
  6. class ResponseBulkHandler implements IResponseHandler {
  7. public function handle(IConnectionComposable $connection, $lengthString) {
  8. $length = (int) $lengthString;
  9. if ($length != $lengthString) {
  10. Utils::onCommunicationException(new ProtocolException(
  11. $connection, "Cannot parse '$length' as data length"
  12. ));
  13. }
  14. if ($length >= 0) {
  15. return substr($connection->readBytes($length + 2), 0, -2);
  16. }
  17. if ($length == -1) {
  18. return null;
  19. }
  20. }
  21. }