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 {
16 private $method;
17
19 private $uri;
20
22 private $protocolVersion;
23
25 private $body;
26
28 private $serverParams;
29
31 private $cookieParams;
32
34 private $queryParams;
35
37 private $uploadedFiles;
38
40 private $postParams;
41
60 public function __construct( $params = [] ) {
61 $this->method = $params['method'] ?? 'GET';
62 $this->uri = $params['uri'] ?? new Uri;
63 $this->protocolVersion = $params['protocolVersion'] ?? '1.1';
64 $this->body = new StringStream( $params['bodyContents'] ?? '' );
65 $this->serverParams = $params['serverParams'] ?? [];
66 $this->cookieParams = $params['cookieParams'] ?? [];
67 $this->queryParams = $params['queryParams'] ?? [];
68 $this->uploadedFiles = $params['uploadedFiles'] ?? [];
69 $this->postParams = $params['postParams'] ?? [];
70 $this->setPathParams( $params['pathParams'] ?? [] );
71 $this->setHeaders( $params['headers'] ?? [] );
72 $this->setParsedBody( $params['parsedBody'] ?? null );
73 parent::__construct( $params['cookiePrefix'] ?? '' );
74 }
75
76 public function getMethod() {
77 return $this->method;
78 }
79
80 public function getUri() {
81 return $this->uri;
82 }
83
84 public function getProtocolVersion() {
85 return $this->protocolVersion;
86 }
87
88 public function getBody() {
89 return $this->body;
90 }
91
92 public function getServerParams() {
93 return $this->serverParams;
94 }
95
96 public function getCookieParams() {
97 return $this->cookieParams;
98 }
99
100 public function getQueryParams() {
101 return $this->queryParams;
102 }
103
104 public function getUploadedFiles() {
105 return $this->uploadedFiles;
106 }
107
108 public function getPostParams() {
109 return $this->postParams;
110 }
111
112 public function hasBody(): bool {
113 if ( parent::hasBody() ) {
114 return true;
115 }
116
117 if ( $this->parsedBody !== null ) {
118 return true;
119 }
120
121 if ( $this->postParams !== [] ) {
122 return true;
123 }
124
125 if ( $this->getBody()->getSize() > 0 ) {
126 return true;
127 }
128
129 return false;
130 }
131
132}
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.