MediaWiki master
SimpleHandler.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Rest;
4
5use LogicException;
6
16abstract class SimpleHandler extends Handler {
18 public function execute() {
19 $paramSettings = $this->getParamSettings();
20 $validatedParams = $this->getValidatedParams();
21 $unvalidatedParams = [];
22 $params = [];
23 foreach ( $this->getRequest()->getPathParams() as $name => $value ) {
24 $source = $paramSettings[$name][self::PARAM_SOURCE] ?? 'unknown';
25 if ( $source !== 'path' ) {
26 $unvalidatedParams[] = $name;
27 $params[] = $value;
28 } else {
29 $params[] = $validatedParams[$name];
30 }
31 }
32
33 if ( $unvalidatedParams ) {
34 throw new LogicException(
35 'Path parameters were not validated: ' . implode( ', ', $unvalidatedParams )
36 );
37 }
38
39 // @phan-suppress-next-line PhanUndeclaredMethod
40 return $this->run( ...$params );
41 }
42}
Base class for REST route handlers.
Definition Handler.php:25
getParamSettings()
Fetch ParamValidator settings for parameters.
Definition Handler.php:708
getRequest()
Get the current request.
Definition Handler.php:371
getValidatedParams()
Fetch the validated parameters.
Definition Handler.php:1264
A handler base class which unpacks parameters from the path template and passes them as formal parame...
execute()
Execute the handler.This is called after parameter validation. The return value can either be a Respo...
$source