RequestInterface.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace Psr\Http\Message;
  3. /**
  4. * Representation of an outgoing, client-side request.
  5. *
  6. * Per the HTTP specification, this interface includes properties for
  7. * each of the following:
  8. *
  9. * - Protocol version
  10. * - HTTP method
  11. * - URI
  12. * - Headers
  13. * - Message body
  14. *
  15. * During construction, implementations MUST attempt to set the Host header from
  16. * a provided URI if no Host header is provided.
  17. *
  18. * Requests are considered immutable; all methods that might change state MUST
  19. * be implemented such that they retain the internal state of the current
  20. * message and return an instance that contains the changed state.
  21. */
  22. interface RequestInterface extends MessageInterface
  23. {
  24. /**
  25. * Retrieves the message's request target.
  26. *
  27. * Retrieves the message's request-target either as it will appear (for
  28. * clients), as it appeared at request (for servers), or as it was
  29. * specified for the instance (see withRequestTarget()).
  30. *
  31. * In most cases, this will be the origin-form of the composed URI,
  32. * unless a value was provided to the concrete implementation (see
  33. * withRequestTarget() below).
  34. *
  35. * If no URI is available, and no request-target has been specifically
  36. * provided, this method MUST return the string "/".
  37. *
  38. * @return string
  39. */
  40. public function getRequestTarget();
  41. /**
  42. * Return an instance with the specific request-target.
  43. *
  44. * If the request needs a non-origin-form request-target — e.g., for
  45. * specifying an absolute-form, authority-form, or asterisk-form —
  46. * this method may be used to create an instance with the specified
  47. * request-target, verbatim.
  48. *
  49. * This method MUST be implemented in such a way as to retain the
  50. * immutability of the message, and MUST return an instance that has the
  51. * changed request target.
  52. *
  53. * @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
  54. * request-target forms allowed in request messages)
  55. * @param mixed $requestTarget
  56. * @return static
  57. */
  58. public function withRequestTarget($requestTarget);
  59. /**
  60. * Retrieves the HTTP method of the request.
  61. *
  62. * @return string Returns the request method.
  63. */
  64. public function getMethod();
  65. /**
  66. * Return an instance with the provided HTTP method.
  67. *
  68. * While HTTP method names are typically all uppercase characters, HTTP
  69. * method names are case-sensitive and thus implementations SHOULD NOT
  70. * modify the given string.
  71. *
  72. * This method MUST be implemented in such a way as to retain the
  73. * immutability of the message, and MUST return an instance that has the
  74. * changed request method.
  75. *
  76. * @param string $method Case-sensitive method.
  77. * @return static
  78. * @throws \InvalidArgumentException for invalid HTTP methods.
  79. */
  80. public function withMethod($method);
  81. /**
  82. * Retrieves the URI instance.
  83. *
  84. * This method MUST return a UriInterface instance.
  85. *
  86. * @link http://tools.ietf.org/html/rfc3986#section-4.3
  87. * @return UriInterface Returns a UriInterface instance
  88. * representing the URI of the request.
  89. */
  90. public function getUri();
  91. /**
  92. * Returns an instance with the provided URI.
  93. *
  94. * This method MUST update the Host header of the returned request by
  95. * default if the URI contains a host component. If the URI does not
  96. * contain a host component, any pre-existing Host header MUST be carried
  97. * over to the returned request.
  98. *
  99. * You can opt-in to preserving the original state of the Host header by
  100. * setting `$preserveHost` to `true`. When `$preserveHost` is set to
  101. * `true`, this method interacts with the Host header in the following ways:
  102. *
  103. * - If the Host header is missing or empty, and the new URI contains
  104. * a host component, this method MUST update the Host header in the returned
  105. * request.
  106. * - If the Host header is missing or empty, and the new URI does not contain a
  107. * host component, this method MUST NOT update the Host header in the returned
  108. * request.
  109. * - If a Host header is present and non-empty, this method MUST NOT update
  110. * the Host header in the returned request.
  111. *
  112. * This method MUST be implemented in such a way as to retain the
  113. * immutability of the message, and MUST return an instance that has the
  114. * new UriInterface instance.
  115. *
  116. * @link http://tools.ietf.org/html/rfc3986#section-4.3
  117. * @param UriInterface $uri New request URI to use.
  118. * @param bool $preserveHost Preserve the original state of the Host header.
  119. * @return static
  120. */
  121. public function withUri(UriInterface $uri, $preserveHost = false);
  122. }