MediaWiki REL1_34
MediaWiki\Rest\Handler Class Reference
Inheritance diagram for MediaWiki\Rest\Handler:
Collaboration diagram for MediaWiki\Rest\Handler:

Public Member Functions

 execute ()
 Execute the handler.
 
 getBodyValidator ( $contentType)
 Fetch the BodyValidator.
 
 getConfig ()
 Get the configuration array for the current route.
 
 getParamSettings ()
 Fetch ParamValidator settings for parameters.
 
 getRequest ()
 Get the current request.
 
 getResponseFactory ()
 Get the ResponseFactory which can be used to generate Response objects.
 
 getValidatedBody ()
 Fetch the validated body.
 
 getValidatedParams ()
 Fetch the validated parameters.
 
 init (Router $router, RequestInterface $request, array $config, ResponseFactory $responseFactory)
 Initialise with dependencies from the Router.
 
 needsReadAccess ()
 Indicates whether this route requires read rights.
 
 needsWriteAccess ()
 Indicates whether this route requires write access.
 
 validate (Validator $restValidator)
 Validate the request parameters/attributes and body.
 

Public Attributes

const PARAM_SOURCE = 'rest-param-source'
 (string) ParamValidator constant to specify the source of the parameter.
 

Protected Member Functions

 getETag ()
 The subclass should override this to provide an ETag for the current request.
 
 getLastModified ()
 The subclass should override this to provide the maximum last modified timestamp for the current request.
 
 getRouter ()
 Get the Router.
 

Private Attributes

array $config
 
RequestInterface $request
 
ResponseFactory $responseFactory
 
Router $router
 
mixed $validatedBody
 
array null $validatedParams
 

Detailed Description

Definition at line 9 of file Handler.php.

Member Function Documentation

◆ execute()

MediaWiki\Rest\Handler::execute ( )
abstract

Execute the handler.

This is called after parameter validation. The return value can either be a Response or any type accepted by ResponseFactory::createFromReturnValue().

To automatically construct an error response, execute() should throw a RestException. Such exceptions will not be logged like a normal exception.

If execute() throws any other kind of exception, the exception will be logged and a generic 500 error page will be shown.

Returns
mixed

Reimplemented in MediaWiki\Rest\SimpleHandler.

◆ getBodyValidator()

MediaWiki\Rest\Handler::getBodyValidator (   $contentType)

Fetch the BodyValidator.

Parameters
string$contentTypeContent type of the request.
Returns
BodyValidator

Definition at line 121 of file Handler.php.

Referenced by MediaWiki\Rest\Validator\Validator\validateBody().

◆ getConfig()

MediaWiki\Rest\Handler::getConfig ( )

Get the configuration array for the current route.

The return type declaration causes it to raise a fatal error if init() has not been called.

Returns
array

Definition at line 73 of file Handler.php.

◆ getETag()

MediaWiki\Rest\Handler::getETag ( )
protected

The subclass should override this to provide an ETag for the current request.

This is called before execute() in order to decide whether to send a 304.

See RFC 7232 ยง 2.3 for semantics.

Returns
string|null

Definition at line 167 of file Handler.php.

◆ getLastModified()

MediaWiki\Rest\Handler::getLastModified ( )
protected

The subclass should override this to provide the maximum last modified timestamp for the current request.

This is called before execute() in order to decide whether to send a 304.

The timestamp can be in any format accepted by ConvertibleTimestamp, or null to indicate that the timestamp is unknown.

Returns
bool|string|int|float|\DateTime|null

Definition at line 154 of file Handler.php.

◆ getParamSettings()

MediaWiki\Rest\Handler::getParamSettings ( )

Fetch ParamValidator settings for parameters.

Every setting must include self::PARAM_SOURCE to specify which part of the request is to contain the parameter.

Returns
array[] Associative array mapping parameter names to ParamValidator settings arrays

Reimplemented in MediaWiki\Rest\Handler\HelloHandler.

Definition at line 112 of file Handler.php.

Referenced by MediaWiki\Rest\SimpleHandler\execute().

◆ getRequest()

MediaWiki\Rest\Handler::getRequest ( )

Get the current request.

The return type declaration causes it to raise a fatal error if init() has not yet been called.

Returns
RequestInterface

Definition at line 62 of file Handler.php.

Referenced by MediaWiki\Rest\SimpleHandler\execute().

◆ getResponseFactory()

MediaWiki\Rest\Handler::getResponseFactory ( )

Get the ResponseFactory which can be used to generate Response objects.

This will raise a fatal error if init() has not been called.

Returns
ResponseFactory

Definition at line 84 of file Handler.php.

◆ getRouter()

MediaWiki\Rest\Handler::getRouter ( )
protected

Get the Router.

The return type declaration causes it to raise a fatal error if init() has not yet been called.

Definition at line 52 of file Handler.php.

◆ getValidatedBody()

MediaWiki\Rest\Handler::getValidatedBody ( )

Fetch the validated body.

Returns
mixed Value returned by the body validator, or null if validateParams() was not called yet, validation failed, there was no body, or the body was form data.

Definition at line 140 of file Handler.php.

◆ getValidatedParams()

MediaWiki\Rest\Handler::getValidatedParams ( )

Fetch the validated parameters.

Returns
array|null Array mapping parameter names to validated values, or null if validateParams() was not called yet or validation failed.

Definition at line 131 of file Handler.php.

Referenced by MediaWiki\Rest\SimpleHandler\execute().

◆ init()

MediaWiki\Rest\Handler::init ( Router  $router,
RequestInterface  $request,
array  $config,
ResponseFactory  $responseFactory 
)

Initialise with dependencies from the Router.

This is called after construction.

Definition at line 39 of file Handler.php.

◆ needsReadAccess()

MediaWiki\Rest\Handler::needsReadAccess ( )

Indicates whether this route requires read rights.

The handler should override this if it does not need to read from the wiki. This is uncommon, but may be useful for login and other account management APIs.

Returns
bool

Definition at line 180 of file Handler.php.

◆ needsWriteAccess()

MediaWiki\Rest\Handler::needsWriteAccess ( )

Indicates whether this route requires write access.

The handler should override this if the route does not need to write to the database.

This should return true for routes that may require synchronous database writes. Modules that do not need such writes should also not rely on master database access, since only read queries are needed and each master DB is a single point of failure.

Returns
bool

Reimplemented in MediaWiki\Rest\Handler\HelloHandler.

Definition at line 196 of file Handler.php.

◆ validate()

MediaWiki\Rest\Handler::validate ( Validator  $restValidator)

Validate the request parameters/attributes and body.

If there is a validation failure, a response with an error message should be returned or an HttpException should be thrown.

Parameters
Validator$restValidator
Exceptions
HttpExceptionOn validation failure.

Definition at line 96 of file Handler.php.

References MediaWiki\Rest\Validator\Validator\validateBody(), and MediaWiki\Rest\Validator\Validator\validateParams().

Member Data Documentation

◆ $config

array MediaWiki\Rest\Handler::$config
private

Definition at line 24 of file Handler.php.

◆ $request

RequestInterface MediaWiki\Rest\Handler::$request
private

Definition at line 21 of file Handler.php.

◆ $responseFactory

ResponseFactory MediaWiki\Rest\Handler::$responseFactory
private

Definition at line 27 of file Handler.php.

◆ $router

Router MediaWiki\Rest\Handler::$router
private

Definition at line 18 of file Handler.php.

◆ $validatedBody

mixed MediaWiki\Rest\Handler::$validatedBody
private

Definition at line 33 of file Handler.php.

◆ $validatedParams

array null MediaWiki\Rest\Handler::$validatedParams
private

Definition at line 30 of file Handler.php.

Referenced by MediaWiki\Rest\SimpleHandler\execute().

◆ PARAM_SOURCE

const MediaWiki\Rest\Handler::PARAM_SOURCE = 'rest-param-source'

(string) ParamValidator constant to specify the source of the parameter.

Value must be 'path', 'query', or 'post'.

Definition at line 15 of file Handler.php.

Referenced by MediaWiki\Rest\SimpleHandler\execute(), and MediaWiki\Rest\Validator\Validator\validateParams().


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