MediaWiki master
MediaWiki\Rest\RequestBase Class Reference

Shared code between RequestData and RequestFromGlobals. More...

Inherits MediaWiki\Rest\RequestInterface.

Inherited by MediaWiki\Rest\RequestData, and MediaWiki\Rest\RequestFromGlobals.

Collaboration diagram for MediaWiki\Rest\RequestBase:

Public Member Functions

 __clone ()
 
 __construct ( $cookiePrefix)
 
 getBodyType ()
 
 getCookie ( $name, $default=null)
 Add the cookie prefix to a specified cookie name and get the value of the resulting prefixed cookie.
 
 getCookiePrefix ()
 Get the current cookie prefix.
 
 getHeader ( $name)
 Retrieves a message header value by the given case-insensitive name.
 
 getHeaderLine ( $name)
 Retrieves a comma-separated string of the values for a single header.
 
 getHeaders ()
 Retrieves all message header values.
 
 getParsedBody ()
 
 getPathParam ( $name)
 Retrieve a single path parameter.
 
 getPathParams ()
 Get the parameters derived from the path template match.
 
 hasBody ()
 Return true if the client provided a content-length header or a transfer-encoding header.
 
 hasHeader ( $name)
 Checks if a header exists by the given case-insensitive name.
 
 setHeaders ( $headers)
 Erase any existing headers and replace them with the specified header lines.
 
 setParsedBody (?array $data)
 
 setPathParams ( $params)
 Erase all path parameters from the object and set the parameter array to the one specified.
 
- Public Member Functions inherited from MediaWiki\Rest\RequestInterface
 getBody ()
 Gets the body of the message.
 
 getCookieParams ()
 Retrieve cookies.
 
 getMethod ()
 Retrieves the HTTP method of the request.
 
 getPostParams ()
 Retrieve POST form parameters.
 
 getProtocolVersion ()
 Retrieves the HTTP protocol version as a string.
 
 getQueryParams ()
 Retrieve query string arguments.
 
 getServerParams ()
 Retrieve server parameters.
 
 getUploadedFiles ()
 Retrieve normalized file upload data.
 
 getUri ()
 Retrieves the URI instance.
 

Protected Member Functions

 initHeaders ()
 Override this in the implementation class if lazy initialisation of header values is desired.
 

Protected Attributes

array $parsedBody
 

Detailed Description

Shared code between RequestData and RequestFromGlobals.

Definition at line 8 of file RequestBase.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\RequestBase::__construct (   $cookiePrefix)
Access: internal
Parameters
string$cookiePrefix

Reimplemented in MediaWiki\Rest\RequestData, and MediaWiki\Rest\RequestFromGlobals.

Definition at line 26 of file RequestBase.php.

Member Function Documentation

◆ __clone()

MediaWiki\Rest\RequestBase::__clone ( )

Definition at line 39 of file RequestBase.php.

◆ getBodyType()

MediaWiki\Rest\RequestBase::getBodyType ( )

Implements MediaWiki\Rest\RequestInterface.

Definition at line 122 of file RequestBase.php.

◆ getCookie()

MediaWiki\Rest\RequestBase::getCookie (   $name,
  $default = null 
)

Add the cookie prefix to a specified cookie name and get the value of the resulting prefixed cookie.

If the cookie does not exist, $default is returned.

Parameters
string$name
mixed | null$default
Returns
mixed The cookie value as a string, or $default

Implements MediaWiki\Rest\RequestInterface.

Definition at line 104 of file RequestBase.php.

References MediaWiki\Rest\RequestInterface\getCookieParams(), and MediaWiki\Rest\RequestBase\getCookiePrefix().

◆ getCookiePrefix()

MediaWiki\Rest\RequestBase::getCookiePrefix ( )

Get the current cookie prefix.

Returns
string

Implements MediaWiki\Rest\RequestInterface.

Definition at line 100 of file RequestBase.php.

Referenced by MediaWiki\Rest\RequestBase\getCookie().

◆ getHeader()

MediaWiki\Rest\RequestBase::getHeader (   $name)

Retrieves a message header value by the given case-insensitive name.

This method returns an array of all the header values of the given case-insensitive header name.

If the header does not appear in the message, this method MUST return an empty array.

A single header value may be a string containing a comma-separated list. Lists will not necessarily be split into arrays. See the comment on HeaderContainer::convertToListAndString().

Parameters
string$nameCase-insensitive header field name.
Returns
string[] An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 67 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\initHeaders().

◆ getHeaderLine()

MediaWiki\Rest\RequestBase::getHeaderLine (   $name)

Retrieves a comma-separated string of the values for a single header.

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method MUST return an empty string.

Parameters
string$nameCase-insensitive header field name.
Returns
string A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 81 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\initHeaders().

◆ getHeaders()

MediaWiki\Rest\RequestBase::getHeaders ( )

Retrieves all message header values.

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

A single header value may be a string containing a comma-separated list. Lists will not necessarily be split into arrays. See the comment on HeaderContainer::convertToListAndString().

Returns
string[][] Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 60 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\initHeaders().

◆ getParsedBody()

MediaWiki\Rest\RequestBase::getParsedBody ( )

Implements MediaWiki\Rest\RequestInterface.

Definition at line 114 of file RequestBase.php.

◆ getPathParam()

MediaWiki\Rest\RequestBase::getPathParam (   $name)

Retrieve a single path parameter.

Retrieves a single path parameter as described in getPathParams(). If the attribute has not been previously set, returns null.

See also
getPathParams()
Parameters
string$nameThe parameter name.
Returns
string|null

Implements MediaWiki\Rest\RequestInterface.

Definition at line 96 of file RequestBase.php.

◆ getPathParams()

MediaWiki\Rest\RequestBase::getPathParams ( )

Get the parameters derived from the path template match.

Returns
string[]

Implements MediaWiki\Rest\RequestInterface.

Definition at line 92 of file RequestBase.php.

◆ hasBody()

MediaWiki\Rest\RequestBase::hasBody ( )

Return true if the client provided a content-length header or a transfer-encoding header.

See also
https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length
Returns
bool

Implements MediaWiki\Rest\RequestInterface.

Reimplemented in MediaWiki\Rest\RequestData.

Definition at line 140 of file RequestBase.php.

◆ hasHeader()

MediaWiki\Rest\RequestBase::hasHeader (   $name)

Checks if a header exists by the given case-insensitive name.

Parameters
string$nameCase-insensitive header field name.
Returns
bool Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 74 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\initHeaders().

◆ initHeaders()

MediaWiki\Rest\RequestBase::initHeaders ( )
protected

Override this in the implementation class if lazy initialisation of header values is desired.

It should call setHeaders().

Access: internal

Reimplemented in MediaWiki\Rest\RequestFromGlobals.

Definition at line 36 of file RequestBase.php.

Referenced by MediaWiki\Rest\RequestBase\getHeader(), MediaWiki\Rest\RequestBase\getHeaderLine(), MediaWiki\Rest\RequestBase\getHeaders(), and MediaWiki\Rest\RequestBase\hasHeader().

◆ setHeaders()

MediaWiki\Rest\RequestBase::setHeaders (   $headers)

Erase any existing headers and replace them with the specified header lines.

Call this either from the constructor or from initHeaders() of the implementing class.

Access: internal
Parameters
string[]$headersThe header lines

Definition at line 55 of file RequestBase.php.

References MediaWiki\Rest\HeaderContainer\resetHeaders().

Referenced by MediaWiki\Rest\RequestData\__construct(), and MediaWiki\Rest\RequestFromGlobals\initHeaders().

◆ setParsedBody()

MediaWiki\Rest\RequestBase::setParsedBody ( ?array  $data)

Implements MediaWiki\Rest\RequestInterface.

Definition at line 118 of file RequestBase.php.

Referenced by MediaWiki\Rest\RequestData\__construct().

◆ setPathParams()

MediaWiki\Rest\RequestBase::setPathParams (   $params)

Erase all path parameters from the object and set the parameter array to the one specified.

Parameters
string[]$params

Implements MediaWiki\Rest\RequestInterface.

Definition at line 88 of file RequestBase.php.

References $params.

Referenced by MediaWiki\Rest\RequestData\__construct().

Member Data Documentation

◆ $parsedBody

array MediaWiki\Rest\RequestBase::$parsedBody
protected

Definition at line 20 of file RequestBase.php.


The documentation for this class was generated from the following file: