ResponseError.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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;
  11. /**
  12. * Represents an error returned by Redis (-ERR replies) during the execution
  13. * of a command on the server.
  14. *
  15. * @author Daniele Alessandri <suppakilla@gmail.com>
  16. */
  17. class ResponseError implements ResponseErrorInterface
  18. {
  19. private $message;
  20. /**
  21. * @param string $message Error message returned by Redis
  22. */
  23. public function __construct($message)
  24. {
  25. $this->message = $message;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function getMessage()
  31. {
  32. return $this->message;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getErrorType()
  38. {
  39. list($errorType, ) = explode(' ', $this->getMessage(), 2);
  40. return $errorType;
  41. }
  42. /**
  43. * Converts the object to its string representation.
  44. *
  45. * @return string
  46. */
  47. public function __toString()
  48. {
  49. return $this->getMessage();
  50. }
  51. }