File indexing completed on 2025-01-26 05:29:15
0001 <?php 0002 0003 namespace Psr\Http\Message; 0004 0005 /** 0006 * HTTP messages consist of requests from a client to a server and responses 0007 * from a server to a client. This interface defines the methods common to 0008 * each. 0009 * 0010 * Messages are considered immutable; all methods that might change state MUST 0011 * be implemented such that they retain the internal state of the current 0012 * message and return an instance that contains the changed state. 0013 * 0014 * @link http://www.ietf.org/rfc/rfc7230.txt 0015 * @link http://www.ietf.org/rfc/rfc7231.txt 0016 */ 0017 interface MessageInterface 0018 { 0019 /** 0020 * Retrieves the HTTP protocol version as a string. 0021 * 0022 * The string MUST contain only the HTTP version number (e.g., "1.1", "1.0"). 0023 * 0024 * @return string HTTP protocol version. 0025 */ 0026 public function getProtocolVersion(); 0027 0028 /** 0029 * Return an instance with the specified HTTP protocol version. 0030 * 0031 * The version string MUST contain only the HTTP version number (e.g., 0032 * "1.1", "1.0"). 0033 * 0034 * This method MUST be implemented in such a way as to retain the 0035 * immutability of the message, and MUST return an instance that has the 0036 * new protocol version. 0037 * 0038 * @param string $version HTTP protocol version 0039 * @return static 0040 */ 0041 public function withProtocolVersion($version); 0042 0043 /** 0044 * Retrieves all message header values. 0045 * 0046 * The keys represent the header name as it will be sent over the wire, and 0047 * each value is an array of strings associated with the header. 0048 * 0049 * // Represent the headers as a string 0050 * foreach ($message->getHeaders() as $name => $values) { 0051 * echo $name . ": " . implode(", ", $values); 0052 * } 0053 * 0054 * // Emit headers iteratively: 0055 * foreach ($message->getHeaders() as $name => $values) { 0056 * foreach ($values as $value) { 0057 * header(sprintf('%s: %s', $name, $value), false); 0058 * } 0059 * } 0060 * 0061 * While header names are not case-sensitive, getHeaders() will preserve the 0062 * exact case in which headers were originally specified. 0063 * 0064 * @return string[][] Returns an associative array of the message's headers. Each 0065 * key MUST be a header name, and each value MUST be an array of strings 0066 * for that header. 0067 */ 0068 public function getHeaders(); 0069 0070 /** 0071 * Checks if a header exists by the given case-insensitive name. 0072 * 0073 * @param string $name Case-insensitive header field name. 0074 * @return bool Returns true if any header names match the given header 0075 * name using a case-insensitive string comparison. Returns false if 0076 * no matching header name is found in the message. 0077 */ 0078 public function hasHeader($name); 0079 0080 /** 0081 * Retrieves a message header value by the given case-insensitive name. 0082 * 0083 * This method returns an array of all the header values of the given 0084 * case-insensitive header name. 0085 * 0086 * If the header does not appear in the message, this method MUST return an 0087 * empty array. 0088 * 0089 * @param string $name Case-insensitive header field name. 0090 * @return string[] An array of string values as provided for the given 0091 * header. If the header does not appear in the message, this method MUST 0092 * return an empty array. 0093 */ 0094 public function getHeader($name); 0095 0096 /** 0097 * Retrieves a comma-separated string of the values for a single header. 0098 * 0099 * This method returns all of the header values of the given 0100 * case-insensitive header name as a string concatenated together using 0101 * a comma. 0102 * 0103 * NOTE: Not all header values may be appropriately represented using 0104 * comma concatenation. For such headers, use getHeader() instead 0105 * and supply your own delimiter when concatenating. 0106 * 0107 * If the header does not appear in the message, this method MUST return 0108 * an empty string. 0109 * 0110 * @param string $name Case-insensitive header field name. 0111 * @return string A string of values as provided for the given header 0112 * concatenated together using a comma. If the header does not appear in 0113 * the message, this method MUST return an empty string. 0114 */ 0115 public function getHeaderLine($name); 0116 0117 /** 0118 * Return an instance with the provided value replacing the specified header. 0119 * 0120 * While header names are case-insensitive, the casing of the header will 0121 * be preserved by this function, and returned from getHeaders(). 0122 * 0123 * This method MUST be implemented in such a way as to retain the 0124 * immutability of the message, and MUST return an instance that has the 0125 * new and/or updated header and value. 0126 * 0127 * @param string $name Case-insensitive header field name. 0128 * @param string|string[] $value Header value(s). 0129 * @return static 0130 * @throws \InvalidArgumentException for invalid header names or values. 0131 */ 0132 public function withHeader($name, $value); 0133 0134 /** 0135 * Return an instance with the specified header appended with the given value. 0136 * 0137 * Existing values for the specified header will be maintained. The new 0138 * value(s) will be appended to the existing list. If the header did not 0139 * exist previously, it will be added. 0140 * 0141 * This method MUST be implemented in such a way as to retain the 0142 * immutability of the message, and MUST return an instance that has the 0143 * new header and/or value. 0144 * 0145 * @param string $name Case-insensitive header field name to add. 0146 * @param string|string[] $value Header value(s). 0147 * @return static 0148 * @throws \InvalidArgumentException for invalid header names or values. 0149 */ 0150 public function withAddedHeader($name, $value); 0151 0152 /** 0153 * Return an instance without the specified header. 0154 * 0155 * Header resolution MUST be done without case-sensitivity. 0156 * 0157 * This method MUST be implemented in such a way as to retain the 0158 * immutability of the message, and MUST return an instance that removes 0159 * the named header. 0160 * 0161 * @param string $name Case-insensitive header field name to remove. 0162 * @return static 0163 */ 0164 public function withoutHeader($name); 0165 0166 /** 0167 * Gets the body of the message. 0168 * 0169 * @return StreamInterface Returns the body as a stream. 0170 */ 0171 public function getBody(); 0172 0173 /** 0174 * Return an instance with the specified message body. 0175 * 0176 * The body MUST be a StreamInterface object. 0177 * 0178 * This method MUST be implemented in such a way as to retain the 0179 * immutability of the message, and MUST return a new instance that has the 0180 * new body stream. 0181 * 0182 * @param StreamInterface $body Body. 0183 * @return static 0184 * @throws \InvalidArgumentException When the body is not valid. 0185 */ 0186 public function withBody(StreamInterface $body); 0187 }