MediaWiki  1.34.0
RequestFromGlobals.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Rest;
4 
5 use GuzzleHttp\Psr7\LazyOpenStream;
6 use GuzzleHttp\Psr7\ServerRequest;
7 use GuzzleHttp\Psr7\Uri;
8 
9 // phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
10 
16  private $uri;
17  private $protocol;
18  private $uploadedFiles;
19 
24  public function __construct( $params = [] ) {
25  parent::__construct( $params['cookiePrefix'] ?? '' );
26  }
27 
28  // RequestInterface
29 
30  public function getMethod() {
31  return $_SERVER['REQUEST_METHOD'] ?? 'GET';
32  }
33 
34  public function getUri() {
35  if ( $this->uri === null ) {
36  $this->uri = new Uri( \WebRequest::getGlobalRequestURL() );
37  }
38  return $this->uri;
39  }
40 
41  // MessageInterface
42 
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 );
49  } else {
50  $this->protocol = '1.1';
51  }
52  }
53  return $this->protocol;
54  }
55 
56  protected function initHeaders() {
57  if ( function_exists( 'apache_request_headers' ) ) {
58  $this->setHeaders( apache_request_headers() );
59  } else {
60  $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;
67  }
68  }
69  $this->setHeaders( $headers );
70  }
71  }
72 
73  public function getBody() {
74  return new LazyOpenStream( 'php://input', 'r' );
75  }
76 
77  // ServerRequestInterface
78 
79  public function getServerParams() {
80  return $_SERVER;
81  }
82 
83  public function getCookieParams() {
84  return $_COOKIE;
85  }
86 
87  public function getQueryParams() {
88  return $_GET;
89  }
90 
91  public function getUploadedFiles() {
92  if ( $this->uploadedFiles === null ) {
93  $this->uploadedFiles = ServerRequest::normalizeFiles( $_FILES );
94  }
95  return $this->uploadedFiles;
96  }
97 
98  public function getPostParams() {
99  return $_POST;
100  }
101 }
MediaWiki\Rest\RequestFromGlobals\getUri
getUri()
Retrieves the URI instance.
Definition: RequestFromGlobals.php:34
MediaWiki\Rest\RequestFromGlobals\getServerParams
getServerParams()
Retrieve server parameters.
Definition: RequestFromGlobals.php:79
MediaWiki\Rest\RequestFromGlobals
This is a request class that gets data directly from the superglobals and other global PHP state,...
Definition: RequestFromGlobals.php:15
MediaWiki\Rest\RequestFromGlobals\initHeaders
initHeaders()
Override this in the implementation class if lazy initialisation of header values is desired.
Definition: RequestFromGlobals.php:56
MediaWiki\Rest\RequestFromGlobals\getMethod
getMethod()
Retrieves the HTTP method of the request.
Definition: RequestFromGlobals.php:30
MediaWiki\Rest\RequestFromGlobals\getQueryParams
getQueryParams()
Retrieve query string arguments.
Definition: RequestFromGlobals.php:87
MediaWiki\Rest\RequestFromGlobals\getBody
getBody()
Gets the body of the message.
Definition: RequestFromGlobals.php:73
MediaWiki\Rest
MediaWiki\Rest\RequestBase\setHeaders
setHeaders( $headers)
Erase any existing headers and replace them with the specified header lines.
Definition: RequestBase.php:53
MediaWiki\Rest\RequestFromGlobals\$protocol
$protocol
Definition: RequestFromGlobals.php:17
MediaWiki\Rest\RequestFromGlobals\getPostParams
getPostParams()
Retrieve POST form parameters.
Definition: RequestFromGlobals.php:98
MediaWiki\Rest\RequestFromGlobals\getProtocolVersion
getProtocolVersion()
Retrieves the HTTP protocol version as a string.
Definition: RequestFromGlobals.php:43
MediaWiki\Rest\RequestFromGlobals\getUploadedFiles
getUploadedFiles()
Retrieve normalized file upload data.
Definition: RequestFromGlobals.php:91
MediaWiki\Rest\RequestFromGlobals\$uploadedFiles
$uploadedFiles
Definition: RequestFromGlobals.php:18
WebRequest\getGlobalRequestURL
static getGlobalRequestURL()
Return the path and query string portion of the main request URI.
Definition: WebRequest.php:854
MediaWiki\Rest\RequestBase
Shared code between RequestData and RequestFromGlobals.
Definition: RequestBase.php:8
MediaWiki\Rest\RequestFromGlobals\getCookieParams
getCookieParams()
Retrieve cookies.
Definition: RequestFromGlobals.php:83
MediaWiki\Rest\RequestFromGlobals\__construct
__construct( $params=[])
Definition: RequestFromGlobals.php:24
MediaWiki\Rest\RequestFromGlobals\$uri
$uri
Definition: RequestFromGlobals.php:16