ResponseMultiBulkStreamHandler.php 929 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Protocol\Text;
  11. use Predis\Helpers;
  12. use Predis\Protocol\IResponseHandler;
  13. use Predis\Protocol\ProtocolException;
  14. use Predis\Network\IConnectionComposable;
  15. use Predis\Iterators\MultiBulkResponseSimple;
  16. class ResponseMultiBulkStreamHandler implements IResponseHandler
  17. {
  18. public function handle(IConnectionComposable $connection, $lengthString)
  19. {
  20. $length = (int) $lengthString;
  21. if ($length != $lengthString) {
  22. Helpers::onCommunicationException(new ProtocolException(
  23. $connection, "Cannot parse '$length' as data length"
  24. ));
  25. }
  26. return new MultiBulkResponseSimple($connection, $length);
  27. }
  28. }