1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
<?php
/**
* Copyright (c) 2019 Wikimedia Foundation.
*
* This file is partly derived from PSR-7, which requires the following copyright notice:
*
* Copyright (c) 2014 PHP Framework Interoperability Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @file
*/
namespace MediaWiki\Rest;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
/**
* A request interface similar to PSR-7's ServerRequestInterface
*/
interface RequestInterface {
/** @var string[] HTTP request methods that we expect never to have a payload */
public const NO_BODY_METHODS = [ 'GET', 'HEAD' ];
/** @var string[] HTTP request methods that we expect always to have a payload */
public const BODY_METHODS = [ 'POST', 'PUT' ];
// NOTE: per RFC 7231 (https://www.rfc-editor.org/rfc/rfc7231#section-4.3.5), sending a body
// with the DELETE method "has no defined semantics". We allow it, as it is useful for
// passing the csrf token required by some authentication methods.
public const JSON_CONTENT_TYPE = 'application/json';
public const MULTIPART_FORM_DATA_CONTENT_TYPE = 'multipart/form-data';
public const FORM_URLENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded';
/** @var string[] Content types handled via $_POST */
public const FORM_DATA_CONTENT_TYPES = [
self::FORM_URLENCODED_CONTENT_TYPE,
self::MULTIPART_FORM_DATA_CONTENT_TYPE,
];
/**
* Retrieves the HTTP method of the request.
*
* @return string Returns the request method.
*/
public function getMethod();
/**
* Retrieves the URI instance.
*
* This method MUST return a UriInterface instance.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
* @return UriInterface Returns a UriInterface instance
* representing the URI of the request.
*/
public function getUri();
// MessageInterface
/**
* Retrieves the HTTP protocol version as a string.
*
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion();
/**
* Retrieves all message header values.
*
* The keys represent the header name as it will be sent over the wire, and
* each value is an array of strings associated with the header.
*
* // Represent the headers as a string
* foreach ($message->getHeaders() as $name => $values) {
* echo $name . ": " . implode(", ", $values);
* }
*
* // Emit headers iteratively:
* foreach ($message->getHeaders() as $name => $values) {
* foreach ($values as $value) {
* header(sprintf('%s: %s', $name, $value), false);
* }
* }
*
* While header names are not case-sensitive, getHeaders() will preserve the
* exact case in which headers were originally specified.
*
* A single header value may be a string containing a comma-separated list.
* Lists will not necessarily be split into arrays. See the comment on
* HeaderContainer::convertToListAndString().
*
* @return string[][] Returns an associative array of the message's headers. Each
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders();
/**
* Retrieves a message header value by the given case-insensitive name.
*
* This method returns an array of all the header values of the given
* case-insensitive header name.
*
* If the header does not appear in the message, this method MUST return an
* empty array.
*
* A single header value may be a string containing a comma-separated list.
* Lists will not necessarily be split into arrays. See the comment on
* HeaderContainer::convertToListAndString().
*
* @param string $name Case-insensitive header field name.
* @return string[] An array of string values as provided for the given
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader( $name );
/**
* Checks if a header exists by the given case-insensitive name.
*
* @param string $name Case-insensitive header field name.
* @return bool Returns true if any header names match the given header
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader( $name );
/**
* Retrieves a comma-separated string of the values for a single header.
*
* This method returns all of the header values of the given
* case-insensitive header name as a string concatenated together using
* a comma.
*
* NOTE: Not all header values may be appropriately represented using
* comma concatenation. For such headers, use getHeader() instead
* and supply your own delimiter when concatenating.
*
* If the header does not appear in the message, this method MUST return
* an empty string.
*
* @param string $name Case-insensitive header field name.
* @return string A string of values as provided for the given header
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return an empty string.
*/
public function getHeaderLine( $name );
/**
* Gets the body of the message.
*
* @return StreamInterface Returns the body as a stream.
*/
public function getBody();
// ServerRequestInterface
/**
* Retrieve server parameters.
*
* Retrieves data related to the incoming request environment,
* typically derived from PHP's $_SERVER superglobal. The data IS NOT
* REQUIRED to originate from $_SERVER.
*
* @return array
*/
public function getServerParams();
/**
* Retrieve cookies.
*
* Retrieves cookies sent by the client to the server.
*
* The data MUST be compatible with the structure of the $_COOKIE
* superglobal.
*
* @return array
*/
public function getCookieParams();
/**
* Retrieve query string arguments.
*
* Retrieves the deserialized query string arguments, if any.
*
* Note: the query params might not be in sync with the URI or server
* params. If you need to ensure you are only getting the original
* values, you may need to parse the query string from `getUri()->getQuery()`
* or from the `QUERY_STRING` server param.
*
* @return array
*/
public function getQueryParams();
/**
* Retrieve normalized file upload data.
*
* This method returns upload metadata in a normalized tree, with each leaf
* an instance of Psr\Http\Message\UploadedFileInterface.
*
* @return array An array tree of UploadedFileInterface instances; an empty
* array MUST be returned if no data is present.
*/
public function getUploadedFiles();
// MediaWiki extensions to PSR-7
/**
* Get the parameters derived from the path template match
*
* @return string[]
*/
public function getPathParams();
/**
* Retrieve a single path parameter.
*
* Retrieves a single path parameter as described in getPathParams(). If
* the attribute has not been previously set, returns null.
*
* @see getPathParams()
* @param string $name The parameter name.
* @return string|null
*/
public function getPathParam( $name );
/**
* Erase all path parameters from the object and set the parameter array
* to the one specified.
*
* @param string[] $params
*/
public function setPathParams( $params );
/**
* Get the current cookie prefix
*
* @return string
*/
public function getCookiePrefix();
/**
* Add the cookie prefix to a specified cookie name and get the value of
* the resulting prefixed cookie. If the cookie does not exist, $default
* is returned.
*
* @param string $name
* @param mixed|null $default
* @return mixed The cookie value as a string, or $default
*/
public function getCookie( $name, $default = null );
/**
* Retrieve POST form parameters.
*
* This will return an array of parameters in the format of $_POST.
*
* @return array The deserialized POST parameters
*/
public function getPostParams();
/**
* Returns the parsed body as an associative array.
*
* If setParsedBody() was called on a given RequestInterface object,
* this method must return the data passed to that call.
*
* If setParsedBody() was not called, implementations may return body data
* they get from the runtime environment, or null.
*
* @since 1.42
*
* @return array|null
*/
public function getParsedBody(): ?array;
/**
* Specify the data that subsequent calls to getParsedBody() should return.
*
* This is intended for use by the framework to make a parsed representation
* of the body data known to request handlers.
*
* @since 1.42
*
* @param array|null $data The body data.
*/
public function setParsedBody( ?array $data );
/**
* Returns the MIME type of the request body, according to the
* content-type header. The value returned by this method must be
* a lower-case string with no whitespace and no additional information
* beyond the mime type. In particular, any "parameters" must be stripped
* from the value of the content-type header. See RFC 9110 section 8.3.1.
*
* @since 1.42
*
* @return string|null The request body's mime type, or null if there is
* no request body or there the type was not specified.
*/
public function getBodyType(): ?string;
/**
* Determines whether the request has body data associated with it.
* Note that this method may return true even if the body is empty.
*
* @since 1.42
*
* @return bool
*/
public function hasBody(): bool;
}
|