MediaWiki master
RequestData.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Rest;
4
5use GuzzleHttp\Psr7\Uri;
6use Psr\Http\Message\StreamInterface;
7use Psr\Http\Message\UploadedFileInterface;
8use Psr\Http\Message\UriInterface;
9
14class RequestData extends RequestBase {
15 private $method;
16
18 private $uri;
19
20 private $protocolVersion;
21
23 private $body;
24
25 private $serverParams;
26
27 private $cookieParams;
28
29 private $queryParams;
30
32 private $uploadedFiles;
33
34 private $postParams;
35
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 $this->setParsedBody( $params['parsedBody'] ?? null );
67 parent::__construct( $params['cookiePrefix'] ?? '' );
68 }
69
70 public function getMethod() {
71 return $this->method;
72 }
73
74 public function getUri() {
75 return $this->uri;
76 }
77
78 public function getProtocolVersion() {
79 return $this->protocolVersion;
80 }
81
82 public function getBody() {
83 return $this->body;
84 }
85
86 public function getServerParams() {
87 return $this->serverParams;
88 }
89
90 public function getCookieParams() {
91 return $this->cookieParams;
92 }
93
94 public function getQueryParams() {
95 return $this->queryParams;
96 }
97
98 public function getUploadedFiles() {
99 return $this->uploadedFiles;
100 }
101
102 public function getPostParams() {
103 return $this->postParams;
104 }
105
106 public function hasBody(): bool {
107 if ( parent::hasBody() ) {
108 return true;
109 }
110
111 if ( $this->parsedBody !== null ) {
112 return true;
113 }
114
115 if ( $this->getBody()->getSize() > 0 ) {
116 return true;
117 }
118
119 return false;
120 }
121
122}
array $params
The job parameters.
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
Shared code between RequestData and RequestFromGlobals.
setHeaders( $headers)
Erase any existing headers and replace them with the specified header lines.
setPathParams( $params)
Erase all path parameters from the object and set the parameter array to the one specified.
setParsedBody(?array $data)
Specify the data that subsequent calls to getParsedBody() should return.
This is a Request class that allows data to be injected, for the purposes of testing or internal requ...
getUri()
Retrieves the URI instance.
getMethod()
Retrieves the HTTP method of the request.
getPostParams()
Retrieve POST form parameters.
hasBody()
Return true if the client provided a content-length header or a transfer-encoding header.
getServerParams()
Retrieve server parameters.
getProtocolVersion()
Retrieves the HTTP protocol version as a string.
getUploadedFiles()
Retrieve normalized file upload data.
getCookieParams()
Retrieve cookies.
getBody()
Gets the body of the message.
__construct( $params=[])
Construct a RequestData from an array of parameters.
getQueryParams()
Retrieve query string arguments.
A stream class which uses a string as the underlying storage.