ResponseIntegerHandler.php 862 B

1234567891011121314151617181920212223242526272829303132333435
  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. class ResponseIntegerHandler implements IResponseHandler
  16. {
  17. public function handle(IConnectionComposable $connection, $number)
  18. {
  19. if (is_numeric($number)) {
  20. return (int) $number;
  21. }
  22. if ($number !== 'nil') {
  23. Helpers::onCommunicationException(new ProtocolException(
  24. $connection, "Cannot parse '$number' as numeric response"
  25. ));
  26. }
  27. return null;
  28. }
  29. }