Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SimpleHandler | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
| 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 | /** @inheritDoc */ |
| 19 | public function execute() { |
| 20 | $paramSettings = $this->getParamSettings(); |
| 21 | $validatedParams = $this->getValidatedParams(); |
| 22 | $unvalidatedParams = []; |
| 23 | $params = []; |
| 24 | foreach ( $this->getRequest()->getPathParams() as $name => $value ) { |
| 25 | $source = $paramSettings[$name][self::PARAM_SOURCE] ?? 'unknown'; |
| 26 | if ( $source !== 'path' ) { |
| 27 | $unvalidatedParams[] = $name; |
| 28 | $params[] = $value; |
| 29 | } else { |
| 30 | $params[] = $validatedParams[$name]; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if ( $unvalidatedParams ) { |
| 35 | throw new LogicException( |
| 36 | 'Path parameters were not validated: ' . implode( ', ', $unvalidatedParams ) |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | // @phan-suppress-next-line PhanUndeclaredMethod |
| 41 | return $this->run( ...$params ); |
| 42 | } |
| 43 | } |