Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / includes / Rest / RequestData.php
1 <?php
2
3 namespace MediaWiki\Rest;
4
5 use GuzzleHttp\Psr7\Uri;
6 use Psr\Http\Message\StreamInterface;
7 use Psr\Http\Message\UploadedFileInterface;
8 use Psr\Http\Message\UriInterface;
9
10 /**
11 * This is a Request class that allows data to be injected, for the purposes
12 * of testing or internal requests.
13 */
14 class RequestData extends RequestBase {
15 private $method;
16
17 /** @var UriInterface */
18 private $uri;
19
20 private $protocolVersion;
21
22 /** @var StreamInterface */
23 private $body;
24
25 private $serverParams;
26
27 private $cookieParams;
28
29 private $queryParams;
30
31 /** @var UploadedFileInterface[] */
32 private $uploadedFiles;
33
34 private $postParams;
35
36 /**
37 * Construct a RequestData from an array of parameters.
38 *
39 * @param array $params An associative array of parameters. All parameters
40 * have defaults. Parameters are:
41 * - method: The HTTP method
42 * - uri: The URI
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()
53 */
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'] ?? '' );
67 }
68
69 public function getMethod() {
70 return $this->method;
71 }
72
73 public function getUri() {
74 return $this->uri;
75 }
76
77 public function getProtocolVersion() {
78 return $this->protocolVersion;
79 }
80
81 public function getBody() {
82 return $this->body;
83 }
84
85 public function getServerParams() {
86 return $this->serverParams;
87 }
88
89 public function getCookieParams() {
90 return $this->cookieParams;
91 }
92
93 public function getQueryParams() {
94 return $this->queryParams;
95 }
96
97 public function getUploadedFiles() {
98 return $this->uploadedFiles;
99 }
100
101 public function getPostParams() {
102 return $this->postParams;
103 }
104 }