MediaWiki REL1_34
MediaWiki\Rest\RequestBase Class Reference

Shared code between RequestData and RequestFromGlobals. More...

Inheritance diagram for MediaWiki\Rest\RequestBase:
Collaboration diagram for MediaWiki\Rest\RequestBase:

Public Member Functions

 __clone ()
 
 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.
 
 getPathParam ( $name)
 Retrieve a single path parameter.
 
 getPathParams ()
 Get the parameters derived from the path template match.
 
 hasHeader ( $name)
 Checks if a header exists by the given case-insensitive name.
 
 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

 __construct ( $cookiePrefix)
 
 initHeaders ()
 Override this in the implementation class if lazy initialisation of header values is desired.
 
 setHeaders ( $headers)
 Erase any existing headers and replace them with the specified header lines.
 

Private Attributes

string $cookiePrefix
 
HeaderContainer null $headerCollection
 
array $pathParams = []
 

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)
protected

Member Function Documentation

◆ __clone()

MediaWiki\Rest\RequestBase::__clone ( )

Definition at line 37 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\$headerCollection.

◆ 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 102 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 98 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\$cookiePrefix.

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 65 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 79 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 58 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\initHeaders().

◆ 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 94 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 90 of file RequestBase.php.

References MediaWiki\Rest\RequestBase\$pathParams.

◆ 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 72 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().

Reimplemented in MediaWiki\Rest\RequestFromGlobals.

Definition at line 34 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)
protected

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.

Definition at line 53 of file RequestBase.php.

References MediaWiki\Rest\HeaderContainer\resetHeaders().

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

◆ 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 86 of file RequestBase.php.

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

Member Data Documentation

◆ $cookiePrefix

string MediaWiki\Rest\RequestBase::$cookiePrefix
private

◆ $headerCollection

HeaderContainer null MediaWiki\Rest\RequestBase::$headerCollection
private

Definition at line 12 of file RequestBase.php.

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

◆ $pathParams

array MediaWiki\Rest\RequestBase::$pathParams = []
private

Definition at line 15 of file RequestBase.php.

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


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