| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Rest; |
| 4 |
|
| 5 |
use GuzzleHttp\Psr7\Uri; |
| 6 |
use Psr\Http\Message\StreamInterface; |
| 7 |
use Psr\Http\Message\UploadedFileInterface; |
| 8 |
use Psr\Http\Message\UriInterface; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class RequestData extends RequestBase { |
| 15 |
|
| 16 |
private $method; |
| 17 |
|
| 18 |
|
| 19 |
private $uri; |
| 20 |
|
| 21 |
|
| 22 |
private $protocolVersion; |
| 23 |
|
| 24 |
|
| 25 |
private $body; |
| 26 |
|
| 27 |
|
| 28 |
private $serverParams; |
| 29 |
|
| 30 |
|
| 31 |
private $cookieParams; |
| 32 |
|
| 33 |
|
| 34 |
private $queryParams; |
| 35 |
|
| 36 |
|
| 37 |
private $uploadedFiles; |
| 38 |
|
| 39 |
|
| 40 |
private $postParams; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 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 |
} |