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
77 public function getMethod() {
78 return $this->method;
79 }
80
82 public function getUri() {
83 return $this->uri;
84 }
85
87 public function getProtocolVersion() {
88 return $this->protocolVersion;
89 }
90
92 public function getBody() {
93 return $this->body;
94 }
95
97 public function getServerParams() {
98 return $this->serverParams;
99 }
100
102 public function getCookieParams() {
103 return $this->cookieParams;
104 }
105
107 public function getQueryParams() {
108 return $this->queryParams;
109 }
110
112 public function getUploadedFiles() {
113 return $this->uploadedFiles;
114 }
115
117 public function getPostParams() {
118 return $this->postParams;
119 }
120
122 public function hasBody(): bool {
123 if ( parent::hasBody() ) {
124 return true;
125 }
126
127 if ( $this->parsedBody !== null ) {
128 return true;
129 }
130
131 if ( $this->postParams !== [] ) {
132 return true;
133 }
134
135 if ( $this->getBody()->getSize() > 0 ) {
136 return true;
137 }
138
139 return false;
140 }
141
142}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:68
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.