Debian Codegraph @

includes/Rest/SimpleHandler.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Rest;
4
5 use LogicException;
6
7 /**
8 * A handler base class which unpacks parameters from the path template and
9 * passes them as formal parameters to run().
10 *
11 * run() must be declared in the subclass. It cannot be declared as abstract
12 * here because it has a variable parameter list.
13 *
14 * @stable to extend
15 * @package MediaWiki\Rest
16 */
17 abstract 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 }