1<?php 2 3namespace MediaWiki\Rest; 4 5/** 6 * A handler base class which unpacks parameters from the path template and 7 * passes them as formal parameters to run(). 8 * 9 * run() must be declared in the subclass. It cannot be declared as abstract 10 * here because it has a variable parameter list. 11 * 12 * @stable to extend 13 * @package MediaWiki\Rest 14 */ 15abstract class SimpleHandler extends Handler { 16 public function execute() { 17 $paramSettings = $this->getParamSettings(); 18 $validatedParams = $this->getValidatedParams(); 19 $unvalidatedParams = []; 20 $params = []; 21 foreach ( $this->getRequest()->getPathParams() as $name => $value ) { 22 $source = $paramSettings[$name][self::PARAM_SOURCE] ?? 'unknown'; 23 if ( $source !== 'path' ) { 24 $unvalidatedParams[] = $name; 25 $params[] = $value; 26 } else { 27 $params[] = $validatedParams[$name]; 28 } 29 } 30 31 if ( $unvalidatedParams ) { 32 throw new \LogicException( 33 'Path parameters were not validated: ' . implode( ', ', $unvalidatedParams ) 34 ); 35 } 36 37 // @phan-suppress-next-line PhanUndeclaredMethod 38 return $this->run( ...$params ); 39 } 40} 41