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 readonly string $method;
16
18 private $uri;
19
20 private string $protocolVersion;
21
23 private $body;
24
26 private $serverParams;
27
29 private $cookieParams;
30
32 private $queryParams;
33
35 private $uploadedFiles;
36
38 private $postParams;
39
58 public function __construct( $params = [] ) {
59 $this->method = $params['method'] ?? 'GET';
60 $this->uri = $params['uri'] ?? new Uri;
61 $this->protocolVersion = $params['protocolVersion'] ?? '1.1';
62 $this->body = new StringStream( $params['bodyContents'] ?? '' );
63 $this->serverParams = $params['serverParams'] ?? [];
64 $this->cookieParams = $params['cookieParams'] ?? [];
65 $this->queryParams = $params['queryParams'] ?? [];
66 $this->uploadedFiles = $params['uploadedFiles'] ?? [];
67 $this->postParams = $params['postParams'] ?? [];
68 $this->setPathParams( $params['pathParams'] ?? [] );
69 $this->setHeaders( $params['headers'] ?? [] );
70 $this->setParsedBody( $params['parsedBody'] ?? null );
71 parent::__construct( $params['cookiePrefix'] ?? '' );
72 }
73
75 public function getMethod() {
76 return $this->method;
77 }
78
80 public function getUri() {
81 return $this->uri;
82 }
83
85 public function getProtocolVersion() {
86 return $this->protocolVersion;
87 }
88
90 public function getBody() {
91 return $this->body;
92 }
93
95 public function getServerParams() {
96 return $this->serverParams;
97 }
98
100 public function getCookieParams() {
101 return $this->cookieParams;
102 }
103
105 public function getQueryParams() {
106 return $this->queryParams;
107 }
108
110 public function getUploadedFiles() {
111 return $this->uploadedFiles;
112 }
113
115 public function getPostParams() {
116 return $this->postParams;
117 }
118
120 public function hasBody(): bool {
121 if ( parent::hasBody() ) {
122 return true;
123 }
124
125 if ( $this->parsedBody !== null ) {
126 return true;
127 }
128
129 if ( $this->postParams !== [] ) {
130 return true;
131 }
132
133 if ( $this->getBody()->getSize() > 0 ) {
134 return true;
135 }
136
137 return false;
138 }
139
140}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:71
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.This method MUST return a UriInterface instance.UriInterface Returns a Uri...
getMethod()
Retrieves the HTTP method of the request.string Returns the request method.
getPostParams()
Retrieve POST form parameters.This will return an array of parameters in the format of $_POST....
hasBody()
Return true if the client provided a content-length header or a transfer-encoding header....
getServerParams()
Retrieve server parameters.Retrieves data related to the incoming request environment,...
getProtocolVersion()
Retrieves the HTTP protocol version as a string.The string MUST contain only the HTTP version number ...
getUploadedFiles()
Retrieve normalized file upload data.This method returns upload metadata in a normalized tree,...
getCookieParams()
Retrieve cookies.Retrieves cookies sent by the client to the server.The data MUST be compatible with ...
getBody()
Gets the body of the message.StreamInterface Returns the body as a stream.
__construct( $params=[])
Construct a RequestData from an array of parameters.
getQueryParams()
Retrieve query string arguments.Retrieves the deserialized query string arguments,...
A stream class which uses a string as the underlying storage.