1: <?php
2:
3: namespace Psr\Http\Message;
4:
5: /**
6: * HTTP messages consist of requests from a client to a server and responses
7: * from a server to a client. This interface defines the methods common to
8: * each.
9: *
10: * Messages are considered immutable; all methods that might change state MUST
11: * be implemented such that they retain the internal state of the current
12: * message and return an instance that contains the changed state.
13: *
14: * @see http://www.ietf.org/rfc/rfc7230.txt
15: * @see http://www.ietf.org/rfc/rfc7231.txt
16: */
17: interface MessageInterface
18: {
19: /**
20: * Retrieves the HTTP protocol version as a string.
21: *
22: * The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
23: *
24: * @return string HTTP protocol version
25: */
26: public function getProtocolVersion();
27:
28: /**
29: * Return an instance with the specified HTTP protocol version.
30: *
31: * The version string MUST contain only the HTTP version number (e.g.,
32: * "1.1", "1.0").
33: *
34: * This method MUST be implemented in such a way as to retain the
35: * immutability of the message, and MUST return an instance that has the
36: * new protocol version.
37: *
38: * @param string $version HTTP protocol version
39: *
40: * @return self
41: */
42: public function withProtocolVersion($version);
43:
44: /**
45: * Retrieves all message header values.
46: *
47: * The keys represent the header name as it will be sent over the wire, and
48: * each value is an array of strings associated with the header.
49: *
50: * // Represent the headers as a string
51: * foreach ($message->getHeaders() as $name => $values) {
52: * echo $name . ": " . implode(", ", $values);
53: * }
54: *
55: * // Emit headers iteratively:
56: * foreach ($message->getHeaders() as $name => $values) {
57: * foreach ($values as $value) {
58: * header(sprintf('%s: %s', $name, $value), false);
59: * }
60: * }
61: *
62: * While header names are not case-sensitive, getHeaders() will preserve the
63: * exact case in which headers were originally specified.
64: *
65: * key MUST be a header name, and each value MUST be an array of strings
66: * for that header.
67: *
68: * @return array Returns an associative array of the message's headers. Each
69: */
70: public function getHeaders();
71:
72: /**
73: * Checks if a header exists by the given case-insensitive name.
74: *
75: * name using a case-insensitive string comparison. Returns false if
76: * no matching header name is found in the message.
77: *
78: * @param string $name case-insensitive header field name
79: *
80: * @return bool Returns true if any header names match the given header
81: */
82: public function hasHeader($name);
83:
84: /**
85: * Retrieves a message header value by the given case-insensitive name.
86: *
87: * This method returns an array of all the header values of the given
88: * case-insensitive header name.
89: *
90: * If the header does not appear in the message, this method MUST return an
91: * empty array.
92: *
93: * header. If the header does not appear in the message, this method MUST
94: * return an empty array.
95: *
96: * @param string $name case-insensitive header field name
97: *
98: * @return string[] An array of string values as provided for the given
99: */
100: public function getHeader($name);
101:
102: /**
103: * Retrieves a comma-separated string of the values for a single header.
104: *
105: * This method returns all of the header values of the given
106: * case-insensitive header name as a string concatenated together using
107: * a comma.
108: *
109: * NOTE: Not all header values may be appropriately represented using
110: * comma concatenation. For such headers, use getHeader() instead
111: * and supply your own delimiter when concatenating.
112: *
113: * If the header does not appear in the message, this method MUST return
114: * an empty string.
115: *
116: * concatenated together using a comma. If the header does not appear in
117: * the message, this method MUST return an empty string.
118: *
119: * @param string $name case-insensitive header field name
120: *
121: * @return string A string of values as provided for the given header
122: */
123: public function getHeaderLine($name);
124:
125: /**
126: * Return an instance with the provided value replacing the specified header.
127: *
128: * While header names are case-insensitive, the casing of the header will
129: * be preserved by this function, and returned from getHeaders().
130: *
131: * This method MUST be implemented in such a way as to retain the
132: * immutability of the message, and MUST return an instance that has the
133: * new and/or updated header and value.
134: *
135: * @param string $name case-insensitive header field name
136: * @param string|string[] $value header value(s)
137: *
138: * @throws \InvalidArgumentException for invalid header names or values
139: *
140: * @return self
141: */
142: public function withHeader($name, $value);
143:
144: /**
145: * Return an instance with the specified header appended with the given value.
146: *
147: * Existing values for the specified header will be maintained. The new
148: * value(s) will be appended to the existing list. If the header did not
149: * exist previously, it will be added.
150: *
151: * This method MUST be implemented in such a way as to retain the
152: * immutability of the message, and MUST return an instance that has the
153: * new header and/or value.
154: *
155: * @param string $name case-insensitive header field name to add
156: * @param string|string[] $value header value(s)
157: *
158: * @throws \InvalidArgumentException for invalid header names or values
159: *
160: * @return self
161: */
162: public function withAddedHeader($name, $value);
163:
164: /**
165: * Return an instance without the specified header.
166: *
167: * Header resolution MUST be done without case-sensitivity.
168: *
169: * This method MUST be implemented in such a way as to retain the
170: * immutability of the message, and MUST return an instance that removes
171: * the named header.
172: *
173: * @param string $name case-insensitive header field name to remove
174: *
175: * @return self
176: */
177: public function withoutHeader($name);
178:
179: /**
180: * Gets the body of the message.
181: *
182: * @return StreamInterface returns the body as a stream
183: */
184: public function getBody();
185:
186: /**
187: * Return an instance with the specified message body.
188: *
189: * The body MUST be a StreamInterface object.
190: *
191: * This method MUST be implemented in such a way as to retain the
192: * immutability of the message, and MUST return a new instance that has the
193: * new body stream.
194: *
195: * @param StreamInterface $body body
196: *
197: * @throws \InvalidArgumentException when the body is not valid
198: *
199: * @return self
200: */
201: public function withBody(StreamInterface $body);
202: }
203: