MediaWiki  1.34.0
RequestBase.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Rest;
4 
8 abstract class RequestBase implements RequestInterface {
13 
15  private $pathParams = [];
16 
18  private $cookiePrefix;
19 
24  protected function __construct( $cookiePrefix ) {
25  $this->cookiePrefix = $cookiePrefix;
26  }
27 
34  protected function initHeaders() {
35  }
36 
37  public function __clone() {
38  if ( $this->headerCollection !== null ) {
39  $this->headerCollection = clone $this->headerCollection;
40  }
41  }
42 
53  protected function setHeaders( $headers ) {
54  $this->headerCollection = new HeaderContainer;
55  $this->headerCollection->resetHeaders( $headers );
56  }
57 
58  public function getHeaders() {
59  if ( $this->headerCollection === null ) {
60  $this->initHeaders();
61  }
62  return $this->headerCollection->getHeaders();
63  }
64 
65  public function getHeader( $name ) {
66  if ( $this->headerCollection === null ) {
67  $this->initHeaders();
68  }
69  return $this->headerCollection->getHeader( $name );
70  }
71 
72  public function hasHeader( $name ) {
73  if ( $this->headerCollection === null ) {
74  $this->initHeaders();
75  }
76  return $this->headerCollection->hasHeader( $name );
77  }
78 
79  public function getHeaderLine( $name ) {
80  if ( $this->headerCollection === null ) {
81  $this->initHeaders();
82  }
83  return $this->headerCollection->getHeaderLine( $name );
84  }
85 
86  public function setPathParams( $params ) {
87  $this->pathParams = $params;
88  }
89 
90  public function getPathParams() {
91  return $this->pathParams;
92  }
93 
94  public function getPathParam( $name ) {
95  return $this->pathParams[$name] ?? null;
96  }
97 
98  public function getCookiePrefix() {
99  return $this->cookiePrefix;
100  }
101 
102  public function getCookie( $name, $default = null ) {
103  $cookies = $this->getCookieParams();
104  $prefixedName = $this->getCookiePrefix() . $name;
105  if ( array_key_exists( $prefixedName, $cookies ) ) {
106  return $cookies[$prefixedName];
107  } else {
108  return $default;
109  }
110  }
111 }
MediaWiki\Rest\RequestBase\getHeader
getHeader( $name)
Retrieves a message header value by the given case-insensitive name.
Definition: RequestBase.php:65
MediaWiki\Rest\RequestBase\getCookiePrefix
getCookiePrefix()
Get the current cookie prefix.
Definition: RequestBase.php:98
MediaWiki\Rest\RequestBase\getCookie
getCookie( $name, $default=null)
Add the cookie prefix to a specified cookie name and get the value of the resulting prefixed cookie.
Definition: RequestBase.php:102
MediaWiki\Rest\HeaderContainer\resetHeaders
resetHeaders( $headers=[])
Erase any existing headers and replace them with the specified header arrays or values.
Definition: HeaderContainer.php:23
MediaWiki\Rest\RequestBase\hasHeader
hasHeader( $name)
Checks if a header exists by the given case-insensitive name.
Definition: RequestBase.php:72
MediaWiki\Rest\RequestBase\setPathParams
setPathParams( $params)
Erase all path parameters from the object and set the parameter array to the one specified.
Definition: RequestBase.php:86
MediaWiki\Rest\RequestBase\getHeaders
getHeaders()
Retrieves all message header values.
Definition: RequestBase.php:58
MediaWiki\Rest\RequestBase\getHeaderLine
getHeaderLine( $name)
Retrieves a comma-separated string of the values for a single header.
Definition: RequestBase.php:79
MediaWiki\Rest
MediaWiki\Rest\RequestInterface
A request interface similar to PSR-7's ServerRequestInterface.
Definition: RequestInterface.php:39
MediaWiki\Rest\RequestBase\setHeaders
setHeaders( $headers)
Erase any existing headers and replace them with the specified header lines.
Definition: RequestBase.php:53
MediaWiki\Rest\RequestBase\getPathParams
getPathParams()
Get the parameters derived from the path template match.
Definition: RequestBase.php:90
MediaWiki\Rest\RequestBase\getPathParam
getPathParam( $name)
Retrieve a single path parameter.
Definition: RequestBase.php:94
MediaWiki\Rest\RequestBase\__construct
__construct( $cookiePrefix)
Definition: RequestBase.php:24
MediaWiki\Rest\RequestInterface\getCookieParams
getCookieParams()
Retrieve cookies.
MediaWiki\Rest\RequestBase\$cookiePrefix
string $cookiePrefix
Definition: RequestBase.php:18
MediaWiki\Rest\RequestBase\__clone
__clone()
Definition: RequestBase.php:37
MediaWiki\Rest\RequestBase\initHeaders
initHeaders()
Override this in the implementation class if lazy initialisation of header values is desired.
Definition: RequestBase.php:34
MediaWiki\Rest\RequestBase
Shared code between RequestData and RequestFromGlobals.
Definition: RequestBase.php:8
MediaWiki\Rest\RequestBase\$headerCollection
HeaderContainer null $headerCollection
Definition: RequestBase.php:12
MediaWiki\Rest\HeaderContainer
This is a container for storing headers.
Definition: HeaderContainer.php:12
MediaWiki\Rest\RequestBase\$pathParams
array $pathParams
Definition: RequestBase.php:15