ResponseInterface.php 2.6 KB

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