MediaWiki master
MediaWiki\Rest\RequestData Class Reference

This is a Request class that allows data to be injected, for the purposes of testing or internal requests. More...

Inherits MediaWiki\Rest\RequestBase.

Collaboration diagram for MediaWiki\Rest\RequestData:

Public Member Functions

 __construct ( $params=[])
 Construct a RequestData from an array of parameters.
 
 getBody ()
 Gets the body of the message.
Returns
StreamInterface Returns the body as a stream.

 
 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

 
 getMethod ()
 Retrieves the HTTP method of the request.
Returns
string Returns the request method.

 
 getPostParams ()
 Retrieve POST form parameters.This will return an array of parameters in the format of $_POST.
Returns
array The deserialized POST parameters. May be a nested array structure, since the PHP runtime supports nested arrays in $_POST.

 
 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.

 
 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 The deserialized GET parameters. May be a nested array structure, since the PHP runtime supports nested arrays in $_GET.

 
 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

 
 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.

 
 getUri ()
 Retrieves the URI instance.This method MUST return a UriInterface instance.UriInterface Returns a UriInterface instance representing the URI of the request.
 
 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

 
- Public Member Functions inherited from MediaWiki\Rest\RequestBase
 __clone ()
 
 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.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

 
 getCookiePrefix ()
 Get the current cookie prefix.
Returns
string

 
 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.

 
 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.

 
 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.

 
 getParsedBody ()
 Returns the parsed body as an associative array.
 
 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

 
 getPathParams ()
 Get the parameters derived from the path template match.
Returns
string[]

 
 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.

 
 setHeaders ( $headers)
 Erase any existing headers and replace them with the specified header lines.
 
 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.
Parameters
string[]$params

 

Additional Inherited Members

- Public Attributes inherited from MediaWiki\Rest\RequestInterface
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'
 
- Protected Member Functions inherited from MediaWiki\Rest\RequestBase
 initHeaders ()
 Override this in the implementation class if lazy initialisation of header values is desired.
 
- Protected Attributes inherited from MediaWiki\Rest\RequestBase
array $parsedBody = null
 

Detailed Description

This is a Request class that allows data to be injected, for the purposes of testing or internal requests.

Definition at line 14 of file RequestData.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\RequestData::__construct ( $params = [])

Construct a RequestData from an array of parameters.

Parameters
array$paramsAn associative array of parameters. All parameters have defaults. Parameters are:
  • method: The HTTP method
  • uri: The URI
  • protocolVersion: The HTTP protocol version number
  • bodyContents: A string giving the request body
  • serverParams: Equivalent to $_SERVER
  • cookieParams: Equivalent to $_COOKIE
  • queryParams: Equivalent to $_GET
  • uploadedFiles: An array of objects implementing UploadedFileInterface
  • postParams: Equivalent to $_POST
  • pathParams: The path template parameters
  • headers: An array with the key being the header name
  • cookiePrefix: A prefix to add to cookie names in getCookie()

Reimplemented from MediaWiki\Rest\RequestBase.

Definition at line 60 of file RequestData.php.

References MediaWiki\Rest\RequestBase\setHeaders(), MediaWiki\Rest\RequestBase\setParsedBody(), and MediaWiki\Rest\RequestBase\setPathParams().

Member Function Documentation

◆ getBody()

MediaWiki\Rest\RequestData::getBody ( )

Gets the body of the message.

Returns
StreamInterface Returns the body as a stream.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 92 of file RequestData.php.

◆ getCookieParams()

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

Implements MediaWiki\Rest\RequestInterface.

Definition at line 102 of file RequestData.php.

◆ getMethod()

MediaWiki\Rest\RequestData::getMethod ( )

Retrieves the HTTP method of the request.

Returns
string Returns the request method.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 77 of file RequestData.php.

◆ getPostParams()

MediaWiki\Rest\RequestData::getPostParams ( )

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

Returns
array The deserialized POST parameters. May be a nested array structure, since the PHP runtime supports nested arrays in $_POST.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 117 of file RequestData.php.

◆ getProtocolVersion()

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

Implements MediaWiki\Rest\RequestInterface.

Definition at line 87 of file RequestData.php.

◆ getQueryParams()

MediaWiki\Rest\RequestData::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 The deserialized GET parameters. May be a nested array structure, since the PHP runtime supports nested arrays in $_GET.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 107 of file RequestData.php.

◆ getServerParams()

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

Implements MediaWiki\Rest\RequestInterface.

Definition at line 97 of file RequestData.php.

◆ getUploadedFiles()

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

Implements MediaWiki\Rest\RequestInterface.

Definition at line 112 of file RequestData.php.

◆ getUri()

MediaWiki\Rest\RequestData::getUri ( )

Retrieves the URI instance.This method MUST return a UriInterface instance.UriInterface Returns a UriInterface instance representing the URI of the request.

Implements MediaWiki\Rest\RequestInterface.

Definition at line 82 of file RequestData.php.

◆ hasBody()

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

Reimplemented from MediaWiki\Rest\RequestBase.

Definition at line 122 of file RequestData.php.


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