ResponseBulkHandler.php 732 B

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