2019-05-09 01:36:18 +00:00
|
|
|
<?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 {
|
2024-09-07 19:49:56 +00:00
|
|
|
/** @var string */
|
2019-05-09 01:36:18 +00:00
|
|
|
private $method;
|
|
|
|
|
|
|
|
|
|
/** @var UriInterface */
|
|
|
|
|
private $uri;
|
|
|
|
|
|
2024-09-07 19:49:56 +00:00
|
|
|
/** @var string */
|
2019-05-09 01:36:18 +00:00
|
|
|
private $protocolVersion;
|
|
|
|
|
|
|
|
|
|
/** @var StreamInterface */
|
|
|
|
|
private $body;
|
|
|
|
|
|
2024-09-07 19:49:56 +00:00
|
|
|
/** @var array */
|
2019-05-09 01:36:18 +00:00
|
|
|
private $serverParams;
|
|
|
|
|
|
2024-09-07 19:49:56 +00:00
|
|
|
/** @var array */
|
2019-05-09 01:36:18 +00:00
|
|
|
private $cookieParams;
|
|
|
|
|
|
2024-09-07 19:49:56 +00:00
|
|
|
/** @var array */
|
2019-05-09 01:36:18 +00:00
|
|
|
private $queryParams;
|
|
|
|
|
|
|
|
|
|
/** @var UploadedFileInterface[] */
|
|
|
|
|
private $uploadedFiles;
|
|
|
|
|
|
2024-09-07 19:49:56 +00:00
|
|
|
/** @var array */
|
2019-05-09 01:36:18 +00:00
|
|
|
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
|
2019-06-10 21:32:51 +00:00
|
|
|
* - pathParams: The path template parameters
|
2020-05-02 17:40:26 +00:00
|
|
|
* - headers: An array with the key being the header name
|
2019-05-09 01:36:18 +00:00
|
|
|
* - 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'] ?? [];
|
2019-06-10 21:32:51 +00:00
|
|
|
$this->setPathParams( $params['pathParams'] ?? [] );
|
2019-05-09 01:36:18 +00:00
|
|
|
$this->setHeaders( $params['headers'] ?? [] );
|
2024-02-14 13:02:30 +00:00
|
|
|
$this->setParsedBody( $params['parsedBody'] ?? null );
|
2019-05-09 01:36:18 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2024-02-27 12:28:00 +00:00
|
|
|
|
|
|
|
|
public function hasBody(): bool {
|
|
|
|
|
if ( parent::hasBody() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->parsedBody !== null ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-07 18:48:54 +00:00
|
|
|
if ( $this->postParams !== [] ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 11:42:55 +00:00
|
|
|
if ( $this->getBody()->getSize() > 0 ) {
|
2024-02-27 12:28:00 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 01:36:18 +00:00
|
|
|
}
|