MediaWiki REL1_34
Handler.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Rest;
4
8
9abstract class Handler {
10
15 const PARAM_SOURCE = 'rest-param-source';
16
18 private $router;
19
21 private $request;
22
24 private $config;
25
28
31
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
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}
needsWriteAccess()
Indicates whether this route requires write access.
Definition Handler.php:196
getBodyValidator( $contentType)
Fetch the BodyValidator.
Definition Handler.php:121
validate(Validator $restValidator)
Validate the request parameters/attributes and body.
Definition Handler.php:96
getParamSettings()
Fetch ParamValidator settings for parameters.
Definition Handler.php:112
getRequest()
Get the current request.
Definition Handler.php:62
array null $validatedParams
Definition Handler.php:30
getValidatedBody()
Fetch the validated body.
Definition Handler.php:140
getConfig()
Get the configuration array for the current route.
Definition Handler.php:73
RequestInterface $request
Definition Handler.php:21
getRouter()
Get the Router.
Definition Handler.php:52
init(Router $router, RequestInterface $request, array $config, ResponseFactory $responseFactory)
Initialise with dependencies from the Router.
Definition Handler.php:39
getETag()
The subclass should override this to provide an ETag for the current request.
Definition Handler.php:167
getLastModified()
The subclass should override this to provide the maximum last modified timestamp for the current requ...
Definition Handler.php:154
execute()
Execute the handler.
getValidatedParams()
Fetch the validated parameters.
Definition Handler.php:131
needsReadAccess()
Indicates whether this route requires read rights.
Definition Handler.php:180
getResponseFactory()
Get the ResponseFactory which can be used to generate Response objects.
Definition Handler.php:84
const PARAM_SOURCE
(string) ParamValidator constant to specify the source of the parameter.
Definition Handler.php:15
ResponseFactory $responseFactory
Definition Handler.php:27
Generates standardized response objects.
The REST router is responsible for gathering handler configuration, matching an input path and HTTP m...
Definition Router.php:18
Wrapper for ParamValidator.
Definition Validator.php:29
validateParams(array $paramSettings)
Validate parameters.
Definition Validator.php:93
validateBody(RequestInterface $request, Handler $handler)
Validate the body of a request.
return[ 'OATHAuth'=> function(MediaWikiServices $services) { return new OATHAuth($services->getMainConfig(), $services->getDBLoadBalancerFactory());}, 'OATHUserRepository'=> function(MediaWikiServices $services) { global $wgOATHAuthDatabase;$auth=$services->getService( 'OATHAuth');return new OATHUserRepository($services->getDBLoadBalancerFactory() ->getMainLB( $wgOATHAuthDatabase), new \HashBagOStuff(['maxKey'=> 5]), $auth);}]
A request interface similar to PSR-7's ServerRequestInterface.
Interface for validating a request body.