MediaWiki master
MediaWiki\Rest\RequestInterface Interface Reference

A request interface similar to PSR-7's ServerRequestInterface. More...

Inherited by MediaWiki\Rest\RequestBase.

Public Member Functions

 getBody ()
 Gets the body of the message.
 
 getBodyType ()
 Returns the MIME type of the request body, according to the content-type header.
 
 getCookie ( $name, $default=null)
 Add the cookie prefix to a specified cookie name and get the value of the resulting prefixed cookie.
 
 getCookieParams ()
 Retrieve cookies.
 
 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.
 
 getMethod ()
 Retrieves the HTTP method of the request.
 
 getParsedBody ()
 Returns the parsed body as an associative array.
 
 getPathParam ( $name)
 Retrieve a single path parameter.
 
 getPathParams ()
 Get the parameters derived from the path template match.
 
 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.
 
 hasBody ()
 Determines whether the request has body data associated with it.
 
 hasHeader ( $name)
 Checks if a header exists by the given case-insensitive name.
 
 setParsedBody (?array $data)
 Specify the data that subsequent calls to getParsedBody() should return.
 
 setPathParams ( $params)
 Erase all path parameters from the object and set the parameter array to the one specified.
 

Public Attributes

const FORM_URLENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded'
 
const JSON_CONTENT_TYPE = 'application/json'
 
const MULTIPART_FORM_DATA_CONTENT_TYPE = 'multipart/form-data'
 

Detailed Description

A request interface similar to PSR-7's ServerRequestInterface.

Definition at line 39 of file RequestInterface.php.

Member Function Documentation

◆ getBody()

MediaWiki\Rest\RequestInterface::getBody ( )

Gets the body of the message.

Returns
StreamInterface Returns the body as a stream.

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

Referenced by MediaWiki\Rest\Validator\JsonBodyValidator\validateBody(), and MediaWiki\Rest\Validator\Validator\validateBody().

◆ getBodyType()

MediaWiki\Rest\RequestInterface::getBodyType ( )

Returns the MIME type of the request body, according to the content-type header.

The value returned by this method must be a lower-case string with no whitespace and no additional information beyond the mime type. In particular, any "parameters" must be stripped from the value of the content-type header. See RFC 9110 section 8.3.1.

Since
1.42
Returns
string|null The request body's mime type, or null if there is no request body or there the type was not specified.

Implemented in MediaWiki\Rest\RequestBase.

◆ getCookie()

MediaWiki\Rest\RequestInterface::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

Implemented in MediaWiki\Rest\RequestBase.

◆ getCookieParams()

MediaWiki\Rest\RequestInterface::getCookieParams ( )

Retrieve cookies.

Retrieves cookies sent by the client to the server.

The data MUST be compatible with the structure of the $_COOKIE superglobal.

Returns
array

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

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

◆ getCookiePrefix()

MediaWiki\Rest\RequestInterface::getCookiePrefix ( )

Get the current cookie prefix.

Returns
string

Implemented in MediaWiki\Rest\RequestBase.

◆ getHeader()

MediaWiki\Rest\RequestInterface::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.

Implemented in MediaWiki\Rest\RequestBase.

Referenced by MediaWiki\Rest\CorsUtils\authorize(), and MediaWiki\Rest\ConditionalHeaderUtil\checkPreconditions().

◆ getHeaderLine()

MediaWiki\Rest\RequestInterface::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.

Implemented in MediaWiki\Rest\RequestBase.

Referenced by MediaWiki\Rest\Handler\PageHTMLHandler\postValidationSetup(), and MediaWiki\Rest\Validator\Validator\validateBody().

◆ getHeaders()

MediaWiki\Rest\RequestInterface::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.

Implemented in MediaWiki\Rest\RequestBase.

◆ getMethod()

MediaWiki\Rest\RequestInterface::getMethod ( )

Retrieves the HTTP method of the request.

Returns
string Returns the request method.

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

Referenced by MediaWiki\Rest\ConditionalHeaderUtil\checkPreconditions(), and MediaWiki\Rest\Validator\Validator\validateBody().

◆ getParsedBody()

MediaWiki\Rest\RequestInterface::getParsedBody ( )

Returns the parsed body as an associative array.

If setParsedBody() was called on a given RequestInterface object, this method must return the data passed to that call.

If setParsedBody() was not called, implementations may return body data they get from the runtime environment, or null.

Since
1.42
Returns
array|null

Implemented in MediaWiki\Rest\RequestBase.

Referenced by MediaWiki\Rest\Handler\initForExecute().

◆ getPathParam()

MediaWiki\Rest\RequestInterface::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

Implemented in MediaWiki\Rest\RequestBase.

◆ getPathParams()

MediaWiki\Rest\RequestInterface::getPathParams ( )

Get the parameters derived from the path template match.

Returns
string[]

Implemented in MediaWiki\Rest\RequestBase.

◆ getPostParams()

MediaWiki\Rest\RequestInterface::getPostParams ( )

Retrieve POST form parameters.

This will return an array of parameters in the format of $_POST.

Returns
array The deserialized POST parameters

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

◆ getProtocolVersion()

MediaWiki\Rest\RequestInterface::getProtocolVersion ( )

Retrieves the HTTP protocol version as a string.

The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Returns
string HTTP protocol version.

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

◆ getQueryParams()

MediaWiki\Rest\RequestInterface::getQueryParams ( )

Retrieve query string arguments.

Retrieves the deserialized query string arguments, if any.

Note: the query params might not be in sync with the URI or server params. If you need to ensure you are only getting the original values, you may need to parse the query string from getUri()->getQuery() or from the QUERY_STRING server param.

Returns
array

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

◆ getServerParams()

MediaWiki\Rest\RequestInterface::getServerParams ( )

Retrieve server parameters.

Retrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.

Returns
array

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

◆ getUploadedFiles()

MediaWiki\Rest\RequestInterface::getUploadedFiles ( )

Retrieve normalized file upload data.

This method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.

Returns
array An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.

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

◆ getUri()

MediaWiki\Rest\RequestInterface::getUri ( )

Retrieves the URI instance.

This method MUST return a UriInterface instance.

UriInterface Returns a UriInterface instance representing the URI of the request.

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

◆ hasBody()

MediaWiki\Rest\RequestInterface::hasBody ( )

Determines whether the request has body data associated with it.

Note that this method may return true even if the body is empty.

Since
1.42
Returns
bool

Implemented in MediaWiki\Rest\RequestBase, and MediaWiki\Rest\RequestData.

◆ hasHeader()

MediaWiki\Rest\RequestInterface::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.

Implemented in MediaWiki\Rest\RequestBase.

Referenced by MediaWiki\Rest\CorsUtils\authorize(), and MediaWiki\Rest\ConditionalHeaderUtil\checkPreconditions().

◆ setParsedBody()

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

Specify the data that subsequent calls to getParsedBody() should return.

This is intended for use by the framework to make a parsed representation of the body data known to request handlers.

Since
1.42
Parameters
array | null$dataThe body data.

Implemented in MediaWiki\Rest\RequestBase.

◆ setPathParams()

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

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

Parameters
string[]$params

Implemented in MediaWiki\Rest\RequestBase.

Member Data Documentation

◆ FORM_URLENCODED_CONTENT_TYPE

const MediaWiki\Rest\RequestInterface::FORM_URLENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded'

Definition at line 52 of file RequestInterface.php.

◆ JSON_CONTENT_TYPE

const MediaWiki\Rest\RequestInterface::JSON_CONTENT_TYPE = 'application/json'

Definition at line 50 of file RequestInterface.php.

◆ MULTIPART_FORM_DATA_CONTENT_TYPE

const MediaWiki\Rest\RequestInterface::MULTIPART_FORM_DATA_CONTENT_TYPE = 'multipart/form-data'

Definition at line 51 of file RequestInterface.php.


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