ResponseBulkHandler.php 731 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace Predis\Protocols;
  3. use Predis\Utils;
  4. use Predis\CommunicationException;
  5. use Predis\MalformedServerResponse;
  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. Utils::onCommunicationException(new MalformedServerResponse(
  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. }