3 namespace MediaWiki\Rest
;
5 use GuzzleHttp\Psr7\Uri
;
6 use Psr\Http\Message\StreamInterface
;
7 use Psr\Http\Message\UploadedFileInterface
;
8 use Psr\Http\Message\UriInterface
;
11 * This is a Request class that allows data to be injected, for the purposes
12 * of testing or internal requests.
14 class RequestData
extends RequestBase
{
17 /** @var UriInterface */
20 private $protocolVersion;
22 /** @var StreamInterface */
25 private $serverParams;
27 private $cookieParams;
31 /** @var UploadedFileInterface[] */
32 private $uploadedFiles;
37 * Construct a RequestData from an array of parameters.
39 * @param array $params An associative array of parameters. All parameters
40 * have defaults. Parameters are:
41 * - method: The HTTP method
43 * - protocolVersion: The HTTP protocol version number
44 * - bodyContents: A string giving the request body
45 * - serverParams: Equivalent to $_SERVER
46 * - cookieParams: Equivalent to $_COOKIE
47 * - queryParams: Equivalent to $_GET
48 * - uploadedFiles: An array of objects implementing UploadedFileInterface
49 * - postParams: Equivalent to $_POST
50 * - pathParams: The path template parameters
51 * - headers: An array with the the key being the header name
52 * - cookiePrefix: A prefix to add to cookie names in getCookie()
54 public function __construct( $params = [] ) {
55 $this->method
= $params['method'] ??
'GET';
56 $this->uri
= $params['uri'] ??
new Uri
;
57 $this->protocolVersion
= $params['protocolVersion'] ??
'1.1';
58 $this->body
= new StringStream( $params['bodyContents'] ??
'' );
59 $this->serverParams
= $params['serverParams'] ??
[];
60 $this->cookieParams
= $params['cookieParams'] ??
[];
61 $this->queryParams
= $params['queryParams'] ??
[];
62 $this->uploadedFiles
= $params['uploadedFiles'] ??
[];
63 $this->postParams
= $params['postParams'] ??
[];
64 $this->setPathParams( $params['pathParams'] ??
[] );
65 $this->setHeaders( $params['headers'] ??
[] );
66 parent
::__construct( $params['cookiePrefix'] ??
'' );
69 public function getMethod() {
73 public function getUri() {
77 public function getProtocolVersion() {
78 return $this->protocolVersion
;
81 public function getBody() {
85 public function getServerParams() {
86 return $this->serverParams
;
89 public function getCookieParams() {
90 return $this->cookieParams
;
93 public function getQueryParams() {
94 return $this->queryParams
;
97 public function getUploadedFiles() {
98 return $this->uploadedFiles
;
101 public function getPostParams() {
102 return $this->postParams
;