|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Psr\HttpMessage; |
| 4 | + |
| 5 | +/** |
| 6 | + * HTTP messages consist of requests from a client to a server and responses |
| 7 | + * from a server to a client. |
| 8 | + */ |
| 9 | +interface MessageInterface |
| 10 | +{ |
| 11 | + /** |
| 12 | + * Gets the HTTP protocol version as a string containing only the HTTP |
| 13 | + * version (e.g., "1.1", "1.0"). |
| 14 | + * |
| 15 | + * @return string HTTP protocol version. |
| 16 | + */ |
| 17 | + public function getProtocolVersion(); |
| 18 | + |
| 19 | + /** |
| 20 | + * Gets the body of the message. |
| 21 | + * |
| 22 | + * @return StreamInterface|null Returns the body, or null if not set. |
| 23 | + */ |
| 24 | + public function getBody(); |
| 25 | + |
| 26 | + /** |
| 27 | + * Sets the body of the message. |
| 28 | + * |
| 29 | + * The body MUST be a StreamInterface object. Setting the body to null MUST |
| 30 | + * remove the existing body. |
| 31 | + * |
| 32 | + * @param StreamInterface|null $body Body. |
| 33 | + * |
| 34 | + * @return self Returns the message. |
| 35 | + */ |
| 36 | + public function setBody(StreamInterface $body = null); |
| 37 | + |
| 38 | + /** |
| 39 | + * Gets all message headers. |
| 40 | + * |
| 41 | + * The keys represent the header name as it will be sent over the wire, and |
| 42 | + * each value is an array of strings associated with the header. |
| 43 | + * |
| 44 | + * // Represent the headers as a string |
| 45 | + * foreach ($message->getHeaders() as $name => $values) { |
| 46 | + * echo $name . ": " . implode(", ", $values); |
| 47 | + * } |
| 48 | + * |
| 49 | + * @return array Returns an associative array of the message's headers. |
| 50 | + */ |
| 51 | + public function getHeaders(); |
| 52 | + |
| 53 | + /** |
| 54 | + * Checks if a header exists by the given case-insensitive name. |
| 55 | + * |
| 56 | + * @param string $header Case-insensitive header name. |
| 57 | + * |
| 58 | + * @return bool Returns true if any header names match the given header |
| 59 | + * name using a case-insensitive string comparison. Returns false if |
| 60 | + * no matching header name is found in the message. |
| 61 | + */ |
| 62 | + public function hasHeader($header); |
| 63 | + |
| 64 | + /** |
| 65 | + * Retrieve a header by the given case-insensitive name as a string. |
| 66 | + * |
| 67 | + * This method returns all of the header values of the given |
| 68 | + * case-insensitive header name as a string concatenated together using |
| 69 | + * a comma. |
| 70 | + * |
| 71 | + * @param string $header Case-insensitive header name. |
| 72 | + * |
| 73 | + * @return string |
| 74 | + */ |
| 75 | + public function getHeader($header); |
| 76 | + |
| 77 | + /** |
| 78 | + * Retrieve a header by the given case-insensitive name as an array of |
| 79 | + * strings. |
| 80 | + * |
| 81 | + * @param string $header Case-insensitive header name. |
| 82 | + * |
| 83 | + * @return array |
| 84 | + */ |
| 85 | + public function getHeaderAsArray($header); |
| 86 | + |
| 87 | + /** |
| 88 | + * Sets a header, replacing any existing values of any headers with the |
| 89 | + * same case-insensitive name. |
| 90 | + * |
| 91 | + * The header values MUST be a string or an array of strings. |
| 92 | + * |
| 93 | + * @param string $header Header name |
| 94 | + * @param string|array $value Header value(s) |
| 95 | + * |
| 96 | + * @return self Returns the message. |
| 97 | + */ |
| 98 | + public function setHeader($header, $value); |
| 99 | + |
| 100 | + /** |
| 101 | + * Sets headers, replacing any headers that have already been set on the |
| 102 | + * message. |
| 103 | + * |
| 104 | + * The array keys MUST be a string. The array values must be either a |
| 105 | + * string or an array of strings. |
| 106 | + * |
| 107 | + * @param array $headers Headers to set. |
| 108 | + * |
| 109 | + * @return self Returns the message. |
| 110 | + */ |
| 111 | + public function setHeaders(array $headers); |
| 112 | + |
| 113 | + /** |
| 114 | + * Appends a header value to any existing values associated with the |
| 115 | + * given header name. |
| 116 | + * |
| 117 | + * @param string $header Header name to add |
| 118 | + * @param string $value Value of the header |
| 119 | + * |
| 120 | + * @return self |
| 121 | + */ |
| 122 | + public function addHeader($header, $value); |
| 123 | + |
| 124 | + /** |
| 125 | + * Merges in an associative array of headers. |
| 126 | + * |
| 127 | + * Each array key MUST be a string representing the case-insensitive name |
| 128 | + * of a header. Each value MUST be either a string or an array of strings. |
| 129 | + * For each value, the value is appended to any existing header of the same |
| 130 | + * name, or, if a header does not already exist by the given name, then the |
| 131 | + * header is added. |
| 132 | + * |
| 133 | + * @param array $headers Associative array of headers to add to the message |
| 134 | + * |
| 135 | + * @return self |
| 136 | + */ |
| 137 | + public function addHeaders(array $headers); |
| 138 | + |
| 139 | + /** |
| 140 | + * Remove a specific header by case-insensitive name. |
| 141 | + * |
| 142 | + * @param string $header HTTP header to remove |
| 143 | + * |
| 144 | + * @return self |
| 145 | + */ |
| 146 | + public function removeHeader($header); |
| 147 | +} |
0 commit comments