Status.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * @return string
  54. */
  55. public static function get($payload)
  56. {
  57. switch ($payload) {
  58. case 'OK':
  59. case 'QUEUED':
  60. if (!isset(self::$$payload)) {
  61. self::$$payload = new self($payload);
  62. }
  63. return self::$$payload;
  64. default:
  65. return new self($payload);
  66. }
  67. }
  68. }