4 * Copyright (c) 2019 Wikimedia Foundation.
6 * This file is partly derived from PSR-7, which requires the following copyright notice:
8 * Copyright (c) 2014 PHP Framework Interoperability Group
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 namespace MediaWiki\Rest
;
33 use Psr\Http\Message\StreamInterface
;
34 use Psr\Http\Message\UriInterface
;
37 * A request interface similar to PSR-7's ServerRequestInterface
39 interface RequestInterface
{
43 * Retrieves the HTTP method of the request.
45 * @return string Returns the request method.
50 * Retrieves the URI instance.
52 * This method MUST return a UriInterface instance.
54 * @link http://tools.ietf.org/html/rfc3986#section-4.3
55 * @return UriInterface Returns a UriInterface instance
56 * representing the URI of the request.
63 * Retrieves the HTTP protocol version as a string.
65 * The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
67 * @return string HTTP protocol version.
69 function getProtocolVersion();
72 * Retrieves all message header values.
74 * The keys represent the header name as it will be sent over the wire, and
75 * each value is an array of strings associated with the header.
77 * // Represent the headers as a string
78 * foreach ($message->getHeaders() as $name => $values) {
79 * echo $name . ": " . implode(", ", $values);
82 * // Emit headers iteratively:
83 * foreach ($message->getHeaders() as $name => $values) {
84 * foreach ($values as $value) {
85 * header(sprintf('%s: %s', $name, $value), false);
89 * While header names are not case-sensitive, getHeaders() will preserve the
90 * exact case in which headers were originally specified.
92 * A single header value may be a string containing a comma-separated list.
93 * Lists will not necessarily be split into arrays. See the comment on
94 * HeaderContainer::convertToListAndString().
96 * @return string[][] Returns an associative array of the message's headers. Each
97 * key MUST be a header name, and each value MUST be an array of strings
100 function getHeaders();
103 * Retrieves a message header value by the given case-insensitive name.
105 * This method returns an array of all the header values of the given
106 * case-insensitive header name.
108 * If the header does not appear in the message, this method MUST return an
111 * A single header value may be a string containing a comma-separated list.
112 * Lists will not necessarily be split into arrays. See the comment on
113 * HeaderContainer::convertToListAndString().
115 * @param string $name Case-insensitive header field name.
116 * @return string[] An array of string values as provided for the given
117 * header. If the header does not appear in the message, this method MUST
118 * return an empty array.
120 function getHeader( $name );
123 * Checks if a header exists by the given case-insensitive name.
125 * @param string $name Case-insensitive header field name.
126 * @return bool Returns true if any header names match the given header
127 * name using a case-insensitive string comparison. Returns false if
128 * no matching header name is found in the message.
130 function hasHeader( $name );
133 * Retrieves a comma-separated string of the values for a single header.
135 * This method returns all of the header values of the given
136 * case-insensitive header name as a string concatenated together using
139 * NOTE: Not all header values may be appropriately represented using
140 * comma concatenation. For such headers, use getHeader() instead
141 * and supply your own delimiter when concatenating.
143 * If the header does not appear in the message, this method MUST return
146 * @param string $name Case-insensitive header field name.
147 * @return string A string of values as provided for the given header
148 * concatenated together using a comma. If the header does not appear in
149 * the message, this method MUST return an empty string.
151 function getHeaderLine( $name );
154 * Gets the body of the message.
156 * @return StreamInterface Returns the body as a stream.
160 // ServerRequestInterface
163 * Retrieve server parameters.
165 * Retrieves data related to the incoming request environment,
166 * typically derived from PHP's $_SERVER superglobal. The data IS NOT
167 * REQUIRED to originate from $_SERVER.
171 function getServerParams();
176 * Retrieves cookies sent by the client to the server.
178 * The data MUST be compatible with the structure of the $_COOKIE
183 function getCookieParams();
186 * Retrieve query string arguments.
188 * Retrieves the deserialized query string arguments, if any.
190 * Note: the query params might not be in sync with the URI or server
191 * params. If you need to ensure you are only getting the original
192 * values, you may need to parse the query string from `getUri()->getQuery()`
193 * or from the `QUERY_STRING` server param.
197 function getQueryParams();
200 * Retrieve normalized file upload data.
202 * This method returns upload metadata in a normalized tree, with each leaf
203 * an instance of Psr\Http\Message\UploadedFileInterface.
205 * @return array An array tree of UploadedFileInterface instances; an empty
206 * array MUST be returned if no data is present.
208 function getUploadedFiles();
210 // MediaWiki extensions to PSR-7
213 * Get the parameters derived from the path template match
217 function getPathParams();
220 * Retrieve a single path parameter.
222 * Retrieves a single path parameter as described in getPathParams(). If
223 * the attribute has not been previously set, returns null.
225 * @see getPathParams()
226 * @param string $name The parameter name.
227 * @return string|null
229 function getPathParam( $name );
232 * Erase all path parameters from the object and set the parameter array
233 * to the one specified.
235 * @param string[] $params
237 function setPathParams( $params );
240 * Get the current cookie prefix
244 function getCookiePrefix();
247 * Add the cookie prefix to a specified cookie name and get the value of
248 * the resulting prefixed cookie. If the cookie does not exist, $default
251 * @param string $name
252 * @param mixed|null $default
253 * @return mixed The cookie value as a string, or $default
255 function getCookie( $name, $default = null );
258 * Retrieve POST form parameters.
260 * This will return an array of parameters in the format of $_POST.
262 * @return array The deserialized POST parameters
264 function getPostParams();