Status.php 1.6 KB

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