Status.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Response;
  11. /**
  12. * Represents a status response returned by Redis.
  13. *
  14. * @author Daniele Alessandri <suppakilla@gmail.com>
  15. */
  16. class Status implements ResponseInterface
  17. {
  18. private static $OK;
  19. private static $QUEUED;
  20. private $payload;
  21. /**
  22. * @param string $payload Payload of the status response as returned by Redis.
  23. */
  24. public function __construct($payload)
  25. {
  26. $this->payload = $payload;
  27. }
  28. /**
  29. * Converts the response object to its string representation.
  30. *
  31. * @return string
  32. */
  33. public function __toString()
  34. {
  35. return $this->payload;
  36. }
  37. /**
  38. * Returns the payload of status response.
  39. *
  40. * @return string
  41. */
  42. public function getPayload()
  43. {
  44. return $this->payload;
  45. }
  46. /**
  47. * Returns an instance of a status response object.
  48. *
  49. * Common status responses such as OK or QUEUED are cached in order to lower
  50. * the global memory usage especially when using pipelines.
  51. *
  52. * @param string $payload Status response payload.
  53. *
  54. * @return string
  55. */
  56. public static function get($payload)
  57. {
  58. switch ($payload) {
  59. case 'OK':
  60. case 'QUEUED':
  61. if (isset(self::$$payload)) {
  62. return self::$$payload;
  63. }
  64. return self::$$payload = new self($payload);
  65. default:
  66. return new self($payload);
  67. }
  68. }
  69. }