MediaWiki
1.34.0
Handler.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\Rest
;
4
5
use
MediaWiki\Rest\Validator\BodyValidator
;
6
use
MediaWiki\Rest\Validator\NullBodyValidator
;
7
use
MediaWiki\Rest\Validator\Validator
;
8
9
abstract
class
Handler
{
10
15
const
PARAM_SOURCE
=
'rest-param-source'
;
16
18
private
$router
;
19
21
private
$request
;
22
24
private
$config
;
25
27
private
$responseFactory
;
28
30
private
$validatedParams
;
31
33
private
$validatedBody
;
34
39
public
function
init
(
Router
$router
,
RequestInterface
$request
, array
$config
,
40
ResponseFactory
$responseFactory
41
) {
42
$this->router =
$router
;
43
$this->request =
$request
;
44
$this->config =
$config
;
45
$this->responseFactory =
$responseFactory
;
46
}
47
52
protected
function
getRouter
():
Router
{
53
return
$this->router
;
54
}
55
62
public
function
getRequest
():
RequestInterface
{
63
return
$this->request
;
64
}
65
73
public
function
getConfig
(): array {
74
return
$this->config
;
75
}
76
84
public
function
getResponseFactory
():
ResponseFactory
{
85
return
$this->responseFactory
;
86
}
87
96
public
function
validate
(
Validator
$restValidator ) {
97
$validatedParams
= $restValidator->
validateParams
( $this->
getParamSettings
() );
98
$validatedBody
= $restValidator->
validateBody
( $this->request, $this );
99
$this->validatedParams =
$validatedParams
;
100
$this->validatedBody =
$validatedBody
;
101
}
102
112
public
function
getParamSettings
() {
113
return
[];
114
}
115
121
public
function
getBodyValidator
( $contentType ) {
122
return
new
NullBodyValidator
();
123
}
124
131
public
function
getValidatedParams
() {
132
return
$this->validatedParams
;
133
}
134
140
public
function
getValidatedBody
() {
141
return
$this->validatedBody
;
142
}
143
154
protected
function
getLastModified
() {
155
return
null
;
156
}
157
167
protected
function
getETag
() {
168
return
null
;
169
}
170
180
public
function
needsReadAccess
() {
181
return
true
;
182
}
183
196
public
function
needsWriteAccess
() {
197
return
true
;
198
}
199
213
abstract
public
function
execute
();
214
}
MediaWiki\Rest\ResponseFactory
Generates standardized response objects.
Definition:
ResponseFactory.php:18
MediaWiki\Rest\Validator\Validator
Wrapper for ParamValidator.
Definition:
Validator.php:29
MediaWiki\Rest\Handler\getResponseFactory
getResponseFactory()
Get the ResponseFactory which can be used to generate Response objects.
Definition:
Handler.php:84
MediaWiki\Rest\Handler\getParamSettings
getParamSettings()
Fetch ParamValidator settings for parameters.
Definition:
Handler.php:112
MediaWiki\Rest\Handler\getETag
getETag()
The subclass should override this to provide an ETag for the current request.
Definition:
Handler.php:167
MediaWiki\Rest\Handler\$router
Router $router
Definition:
Handler.php:18
MediaWiki\Rest\Handler\$request
RequestInterface $request
Definition:
Handler.php:21
MediaWiki\Rest\Handler\PARAM_SOURCE
const PARAM_SOURCE
(string) ParamValidator constant to specify the source of the parameter.
Definition:
Handler.php:15
MediaWiki\Rest\Handler\validate
validate(Validator $restValidator)
Validate the request parameters/attributes and body.
Definition:
Handler.php:96
MediaWiki\Rest\Handler\execute
execute()
Execute the handler.
MediaWiki\Rest\Handler
Definition:
Handler.php:9
MediaWiki\Rest\Validator\BodyValidator
Interface for validating a request body.
Definition:
BodyValidator.php:11
MediaWiki\Rest\Handler\init
init(Router $router, RequestInterface $request, array $config, ResponseFactory $responseFactory)
Initialise with dependencies from the Router.
Definition:
Handler.php:39
MediaWiki\Rest\Handler\$validatedBody
mixed $validatedBody
Definition:
Handler.php:33
MediaWiki\Rest\Router
The REST router is responsible for gathering handler configuration, matching an input path and HTTP m...
Definition:
Router.php:18
MediaWiki\Rest\Validator\Validator\validateParams
validateParams(array $paramSettings)
Validate parameters.
Definition:
Validator.php:93
MediaWiki\Rest\Handler\getValidatedBody
getValidatedBody()
Fetch the validated body.
Definition:
Handler.php:140
MediaWiki\Rest\Handler\getValidatedParams
getValidatedParams()
Fetch the validated parameters.
Definition:
Handler.php:131
MediaWiki\Rest
MediaWiki\Rest\Handler\getConfig
getConfig()
Get the configuration array for the current route.
Definition:
Handler.php:73
MediaWiki\Rest\Handler\$config
array $config
Definition:
Handler.php:24
MediaWiki\Rest\Validator\NullBodyValidator
Do-nothing body validator.
Definition:
NullBodyValidator.php:10
MediaWiki\Rest\Handler\needsWriteAccess
needsWriteAccess()
Indicates whether this route requires write access.
Definition:
Handler.php:196
MediaWiki\Rest\Handler\$responseFactory
ResponseFactory $responseFactory
Definition:
Handler.php:27
MediaWiki\Rest\RequestInterface
A request interface similar to PSR-7's ServerRequestInterface.
Definition:
RequestInterface.php:39
MediaWiki\Rest\Handler\getRequest
getRequest()
Get the current request.
Definition:
Handler.php:62
MediaWiki\Rest\Validator\Validator\validateBody
validateBody(RequestInterface $request, Handler $handler)
Validate the body of a request.
Definition:
Validator.php:125
MediaWiki\Rest\Handler\getLastModified
getLastModified()
The subclass should override this to provide the maximum last modified timestamp for the current requ...
Definition:
Handler.php:154
MediaWiki\Rest\Handler\getRouter
getRouter()
Get the Router.
Definition:
Handler.php:52
MediaWiki\Rest\Handler\$validatedParams
array null $validatedParams
Definition:
Handler.php:30
MediaWiki\Rest\Handler\needsReadAccess
needsReadAccess()
Indicates whether this route requires read rights.
Definition:
Handler.php:180
MediaWiki\Rest\Handler\getBodyValidator
getBodyValidator( $contentType)
Fetch the BodyValidator.
Definition:
Handler.php:121
includes
Rest
Handler.php
Generated on Thu Dec 19 2019 14:54:46 for MediaWiki by
1.8.16