ResponseBulkHandler.php 746 B

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