3 namespace MediaWiki\Rest
;
5 use GuzzleHttp\Psr7\LazyOpenStream
;
6 use GuzzleHttp\Psr7\ServerRequest
;
7 use GuzzleHttp\Psr7\Uri
;
9 // phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
12 * This is a request class that gets data directly from the superglobals and
13 * other global PHP state, notably php://input.
15 class RequestFromGlobals
extends RequestBase
{
18 private $uploadedFiles;
21 * @param array $params Associative array of parameters:
22 * - cookiePrefix: The prefix for cookie names used by getCookie()
24 public function __construct( $params = [] ) {
25 parent
::__construct( $params['cookiePrefix'] ??
'' );
30 public function getMethod() {
31 return $_SERVER['REQUEST_METHOD'] ??
'GET';
34 public function getUri() {
35 if ( $this->uri
=== null ) {
36 $this->uri
= new Uri( \WebRequest
::getGlobalRequestURL() );
43 public function getProtocolVersion() {
44 if ( $this->protocol
=== null ) {
45 $serverProtocol = $_SERVER['SERVER_PROTOCOL'] ??
'';
46 $prefixLength = strlen( 'HTTP/' );
47 if ( strncmp( $serverProtocol, 'HTTP/', $prefixLength ) === 0 ) {
48 $this->protocol
= substr( $serverProtocol, $prefixLength );
50 $this->protocol
= '1.1';
53 return $this->protocol
;
56 protected function initHeaders() {
57 if ( function_exists( 'apache_request_headers' ) ) {
58 $this->setHeaders( apache_request_headers() );
61 foreach ( $_SERVER as $name => $value ) {
62 if ( substr( $name, 0, 5 ) === 'HTTP_' ) {
63 $name = strtolower( str_replace( '_', '-', substr( $name, 5 ) ) );
64 $headers[$name] = $value;
65 } elseif ( $name === 'CONTENT_LENGTH' ) {
66 $headers['content-length'] = $value;
69 $this->setHeaders( $headers );
73 public function getBody() {
74 return new LazyOpenStream( 'php://input', 'r' );
77 // ServerRequestInterface
79 public function getServerParams() {
83 public function getCookieParams() {
87 public function getQueryParams() {
91 public function getUploadedFiles() {
92 if ( $this->uploadedFiles
=== null ) {
93 $this->uploadedFiles
= ServerRequest
::normalizeFiles( $_FILES );
95 return $this->uploadedFiles
;
98 public function getPostParams() {