MessageInterface.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\HTTP;
  4. /**
  5. * The MessageInterface is the base interface that's used by both
  6. * the RequestInterface and ResponseInterface.
  7. *
  8. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  9. * @author Evert Pot (http://evertpot.com/)
  10. * @license http://sabre.io/license/ Modified BSD License
  11. */
  12. interface MessageInterface
  13. {
  14. /**
  15. * Returns the body as a readable stream resource.
  16. *
  17. * Note that the stream may not be rewindable, and therefore may only be
  18. * read once.
  19. *
  20. * @return resource
  21. */
  22. public function getBodyAsStream();
  23. /**
  24. * Returns the body as a string.
  25. *
  26. * Note that because the underlying data may be based on a stream, this
  27. * method could only work correctly the first time.
  28. */
  29. public function getBodyAsString(): string;
  30. /**
  31. * Returns the message body, as its internal representation.
  32. *
  33. * This could be either a string, a stream or a callback writing the body to php://output
  34. *
  35. * @return resource|string|callable
  36. */
  37. public function getBody();
  38. /**
  39. * Updates the body resource with a new stream.
  40. *
  41. * @param resource|string|callable $body
  42. */
  43. public function setBody($body);
  44. /**
  45. * Returns all the HTTP headers as an array.
  46. *
  47. * Every header is returned as an array, with one or more values.
  48. */
  49. public function getHeaders(): array;
  50. /**
  51. * Will return true or false, depending on if a HTTP header exists.
  52. */
  53. public function hasHeader(string $name): bool;
  54. /**
  55. * Returns a specific HTTP header, based on its name.
  56. *
  57. * The name must be treated as case-insensitive.
  58. * If the header does not exist, this method must return null.
  59. *
  60. * If a header appeared more than once in a HTTP request, this method will
  61. * concatenate all the values with a comma.
  62. *
  63. * Note that this not make sense for all headers. Some, such as
  64. * `Set-Cookie` cannot be logically combined with a comma. In those cases
  65. * you *should* use getHeaderAsArray().
  66. *
  67. * @return string|null
  68. */
  69. public function getHeader(string $name);
  70. /**
  71. * Returns a HTTP header as an array.
  72. *
  73. * For every time the HTTP header appeared in the request or response, an
  74. * item will appear in the array.
  75. *
  76. * If the header did not exist, this method will return an empty array.
  77. *
  78. * @return string[]
  79. */
  80. public function getHeaderAsArray(string $name): array;
  81. /**
  82. * Updates a HTTP header.
  83. *
  84. * The case-sensitivity of the name value must be retained as-is.
  85. *
  86. * If the header already existed, it will be overwritten.
  87. *
  88. * @param string|string[] $value
  89. */
  90. public function setHeader(string $name, $value);
  91. /**
  92. * Sets a new set of HTTP headers.
  93. *
  94. * The headers array should contain headernames for keys, and their value
  95. * should be specified as either a string or an array.
  96. *
  97. * Any header that already existed will be overwritten.
  98. */
  99. public function setHeaders(array $headers);
  100. /**
  101. * Adds a HTTP header.
  102. *
  103. * This method will not overwrite any existing HTTP header, but instead add
  104. * another value. Individual values can be retrieved with
  105. * getHeadersAsArray.
  106. *
  107. * @param string|string[] $value
  108. */
  109. public function addHeader(string $name, $value);
  110. /**
  111. * Adds a new set of HTTP headers.
  112. *
  113. * Any existing headers will not be overwritten.
  114. */
  115. public function addHeaders(array $headers);
  116. /**
  117. * Removes a HTTP header.
  118. *
  119. * The specified header name must be treated as case-insensitive.
  120. * This method should return true if the header was successfully deleted,
  121. * and false if the header did not exist.
  122. */
  123. public function removeHeader(string $name): bool;
  124. /**
  125. * Sets the HTTP version.
  126. *
  127. * Should be 1.0, 1.1 or 2.0.
  128. */
  129. public function setHttpVersion(string $version);
  130. /**
  131. * Returns the HTTP version.
  132. */
  133. public function getHttpVersion(): string;
  134. }