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

Public Member Functions

 applyConditionalResponseHeaders (ResponseInterface $response)
 Modify the response, adding Last-Modified and ETag headers as indicated the values previously returned by ETag and getLastModified(). More...
 
 checkPreconditions ()
 Check the conditional request headers and generate a response if appropriate. More...
 
 execute ()
 Execute the handler. More...
 
 getBodyValidator ( $contentType)
 Fetch the BodyValidator. More...
 
 getConfig ()
 Get the configuration array for the current route. More...
 
 getParamSettings ()
 Fetch ParamValidator settings for parameters. More...
 
 getRequest ()
 Get the current request. More...
 
 getResponseFactory ()
 Get the ResponseFactory which can be used to generate Response objects. More...
 
 getValidatedBody ()
 Fetch the validated body. More...
 
 getValidatedParams ()
 Fetch the validated parameters. More...
 
 init (Router $router, RequestInterface $request, array $config, ResponseFactory $responseFactory)
 Initialise with dependencies from the Router. More...
 
 needsReadAccess ()
 Indicates whether this route requires read rights. More...
 
 needsWriteAccess ()
 Indicates whether this route requires write access. More...
 
 validate (Validator $restValidator)
 Validate the request parameters/attributes and body. More...
 

Public Attributes

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

Protected Member Functions

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

Private Attributes

ConditionalHeaderUtil $conditionalHeaderUtil
 
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

◆ applyConditionalResponseHeaders()

MediaWiki\Rest\Handler::applyConditionalResponseHeaders ( ResponseInterface  $response)

Modify the response, adding Last-Modified and ETag headers as indicated the values previously returned by ETag and getLastModified().

This is called after execute() returns, and may be overridden.

Parameters
ResponseInterface$response

Definition at line 142 of file Handler.php.

◆ checkPreconditions()

MediaWiki\Rest\Handler::checkPreconditions ( )

Check the conditional request headers and generate a response if appropriate.

This is called by the Router before execute() and may be overridden.

Returns
ResponseInterface|null

Definition at line 117 of file Handler.php.

References $response, MediaWiki\Rest\Handler\getETag(), MediaWiki\Rest\Handler\getLastModified(), MediaWiki\Rest\Handler\getRequest(), MediaWiki\Rest\Handler\getResponseFactory(), MediaWiki\Rest\Handler\hasRepresentation(), and MediaWiki\Rest\ConditionalHeaderUtil\setValidators().

◆ 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

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

◆ getBodyValidator()

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

Fetch the BodyValidator.

Parameters
string$contentTypeContent type of the request.
Returns
BodyValidator

Definition at line 164 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 81 of file Handler.php.

References MediaWiki\Rest\Handler\$config.

◆ 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.

This must be a complete ETag, including double quotes.

See RFC 7232 ยง 2.3 for semantics.

Returns
string|null

Definition at line 216 of file Handler.php.

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

◆ 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 201 of file Handler.php.

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

◆ 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

Definition at line 155 of file Handler.php.

Referenced by MediaWiki\Rest\SimpleHandler\execute(), and MediaWiki\Rest\Handler\validate().

◆ 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 70 of file Handler.php.

References MediaWiki\Rest\Handler\$request.

Referenced by MediaWiki\Rest\Handler\checkPreconditions(), and MediaWiki\Rest\SimpleHandler\execute().

◆ getResponseFactory()

MediaWiki\Rest\Handler::getResponseFactory ( )

◆ 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.

Returns
Router

Definition at line 60 of file Handler.php.

References MediaWiki\Rest\Handler\$router.

◆ getValidatedBody()

MediaWiki\Rest\Handler::getValidatedBody ( )

Fetch the validated body.

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

Definition at line 187 of file Handler.php.

References MediaWiki\Rest\Handler\$validatedBody.

◆ getValidatedParams()

MediaWiki\Rest\Handler::getValidatedParams ( )

◆ hasRepresentation()

MediaWiki\Rest\Handler::hasRepresentation ( )
protected

The subclass should override this to indicate whether the resource exists.

This is used for wildcard validators, for example "If-Match: *" fails if the resource does not exist.

Returns
bool|null

Definition at line 227 of file Handler.php.

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

◆ 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 46 of file Handler.php.

References MediaWiki\Rest\Handler\$config, MediaWiki\Rest\Handler\$request, MediaWiki\Rest\Handler\$responseFactory, and MediaWiki\Rest\Handler\$router.

◆ 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 240 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

Definition at line 256 of file Handler.php.

References MediaWiki\Rest\Handler\execute().

◆ 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 104 of file Handler.php.

References MediaWiki\Rest\Handler\$validatedBody, MediaWiki\Rest\Handler\$validatedParams, MediaWiki\Rest\Handler\getParamSettings(), MediaWiki\Rest\Validator\Validator\validateBody(), and MediaWiki\Rest\Validator\Validator\validateParams().

Member Data Documentation

◆ $conditionalHeaderUtil

ConditionalHeaderUtil MediaWiki\Rest\Handler::$conditionalHeaderUtil
private

Definition at line 36 of file Handler.php.

◆ $config

array MediaWiki\Rest\Handler::$config
private

Definition at line 24 of file Handler.php.

Referenced by MediaWiki\Rest\Handler\getConfig(), and MediaWiki\Rest\Handler\init().

◆ $request

RequestInterface MediaWiki\Rest\Handler::$request
private

Definition at line 21 of file Handler.php.

Referenced by MediaWiki\Rest\Handler\getRequest(), and MediaWiki\Rest\Handler\init().

◆ $responseFactory

ResponseFactory MediaWiki\Rest\Handler::$responseFactory
private

◆ $router

Router MediaWiki\Rest\Handler::$router
private

Definition at line 18 of file Handler.php.

Referenced by MediaWiki\Rest\Handler\getRouter(), and MediaWiki\Rest\Handler\init().

◆ $validatedBody

mixed MediaWiki\Rest\Handler::$validatedBody
private

◆ $validatedParams

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

◆ 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\Handler\CompareHandler\getParamSettings(), and MediaWiki\Rest\Validator\Validator\validateParams().


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