1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
<?php
namespace MediaWiki\Rest;
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;
/**
* This is a Request class that allows data to be injected, for the purposes
* of testing or internal requests.
*/
class RequestData extends RequestBase {
/** @var string */
private $method;
/** @var UriInterface */
private $uri;
/** @var string */
private $protocolVersion;
/** @var StreamInterface */
private $body;
/** @var array */
private $serverParams;
/** @var array */
private $cookieParams;
/** @var array */
private $queryParams;
/** @var UploadedFileInterface[] */
private $uploadedFiles;
/** @var array */
private $postParams;
/**
* Construct a RequestData from an array of parameters.
*
* @param array $params An associative array of parameters. All parameters
* have defaults. Parameters are:
* - method: The HTTP method
* - uri: The URI
* - protocolVersion: The HTTP protocol version number
* - bodyContents: A string giving the request body
* - serverParams: Equivalent to $_SERVER
* - cookieParams: Equivalent to $_COOKIE
* - queryParams: Equivalent to $_GET
* - uploadedFiles: An array of objects implementing UploadedFileInterface
* - postParams: Equivalent to $_POST
* - pathParams: The path template parameters
* - headers: An array with the key being the header name
* - cookiePrefix: A prefix to add to cookie names in getCookie()
*/
public function __construct( $params = [] ) {
$this->method = $params['method'] ?? 'GET';
$this->uri = $params['uri'] ?? new Uri;
$this->protocolVersion = $params['protocolVersion'] ?? '1.1';
$this->body = new StringStream( $params['bodyContents'] ?? '' );
$this->serverParams = $params['serverParams'] ?? [];
$this->cookieParams = $params['cookieParams'] ?? [];
$this->queryParams = $params['queryParams'] ?? [];
$this->uploadedFiles = $params['uploadedFiles'] ?? [];
$this->postParams = $params['postParams'] ?? [];
$this->setPathParams( $params['pathParams'] ?? [] );
$this->setHeaders( $params['headers'] ?? [] );
$this->setParsedBody( $params['parsedBody'] ?? null );
parent::__construct( $params['cookiePrefix'] ?? '' );
}
public function getMethod() {
return $this->method;
}
public function getUri() {
return $this->uri;
}
public function getProtocolVersion() {
return $this->protocolVersion;
}
public function getBody() {
return $this->body;
}
public function getServerParams() {
return $this->serverParams;
}
public function getCookieParams() {
return $this->cookieParams;
}
public function getQueryParams() {
return $this->queryParams;
}
public function getUploadedFiles() {
return $this->uploadedFiles;
}
public function getPostParams() {
return $this->postParams;
}
public function hasBody(): bool {
if ( parent::hasBody() ) {
return true;
}
if ( $this->parsedBody !== null ) {
return true;
}
if ( $this->postParams !== [] ) {
return true;
}
if ( $this->getBody()->getSize() > 0 ) {
return true;
}
return false;
}
}
|