No Description

ResponseInterface.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Psr\Http\Message;
  3. /**
  4. * Representation of an outgoing, server-side response.
  5. *
  6. * Per the HTTP specification, this interface includes properties for
  7. * each of the following:
  8. *
  9. * - Protocol version
  10. * - Status code and reason phrase
  11. * - Headers
  12. * - Message body
  13. *
  14. * Responses are considered immutable; all methods that might change state MUST
  15. * be implemented such that they retain the internal state of the current
  16. * message and return an instance that contains the changed state.
  17. */
  18. interface ResponseInterface extends MessageInterface
  19. {
  20. /**
  21. * Gets the response status code.
  22. *
  23. * The status code is a 3-digit integer result code of the server's attempt
  24. * to understand and satisfy the request.
  25. *
  26. * @return int Status code.
  27. */
  28. public function getStatusCode();
  29. /**
  30. * Return an instance with the specified status code and, optionally, reason phrase.
  31. *
  32. * If no reason phrase is specified, implementations MAY choose to default
  33. * to the RFC 7231 or IANA recommended reason phrase for the response's
  34. * status code.
  35. *
  36. * This method MUST be implemented in such a way as to retain the
  37. * immutability of the message, and MUST return an instance that has the
  38. * updated status and reason phrase.
  39. *
  40. * @link http://tools.ietf.org/html/rfc7231#section-6
  41. * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  42. * @param int $code The 3-digit integer result code to set.
  43. * @param string $reasonPhrase The reason phrase to use with the
  44. * provided status code; if none is provided, implementations MAY
  45. * use the defaults as suggested in the HTTP specification.
  46. * @return self
  47. * @throws \InvalidArgumentException For invalid status code arguments.
  48. */
  49. public function withStatus($code, $reasonPhrase = '');
  50. /**
  51. * Gets the response reason phrase associated with the status code.
  52. *
  53. * Because a reason phrase is not a required element in a response
  54. * status line, the reason phrase value MAY be null. Implementations MAY
  55. * choose to return the default RFC 7231 recommended reason phrase (or those
  56. * listed in the IANA HTTP Status Code Registry) for the response's
  57. * status code.
  58. *
  59. * @link http://tools.ietf.org/html/rfc7231#section-6
  60. * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
  61. * @return string Reason phrase; must return an empty string if none present.
  62. */
  63. public function getReasonPhrase();
  64. }