rest: Use ParamValidator library, add BodyValidator
[lhc/web/wiklou.git] / includes / Rest / SimpleHandler.php
index 3718d66..3c19e48 100644 (file)
@@ -14,7 +14,26 @@ namespace MediaWiki\Rest;
  */
 class SimpleHandler extends Handler {
        public function execute() {
-               $params = array_values( $this->getRequest()->getPathParams() );
+               $paramSettings = $this->getParamSettings();
+               $validatedParams = $this->getValidatedParams();
+               $unvalidatedParams = [];
+               $params = [];
+               foreach ( $this->getRequest()->getPathParams() as $name => $value ) {
+                       $source = $paramSettings[$name][self::PARAM_SOURCE] ?? 'unknown';
+                       if ( $source !== 'path' ) {
+                               $unvalidatedParams[] = $name;
+                               $params[] = $value;
+                       } else {
+                               $params[] = $validatedParams[$name];
+                       }
+               }
+
+               if ( $unvalidatedParams ) {
+                       throw new \LogicException(
+                               'Path parameters were not validated: ' . implode( ', ', $unvalidatedParams )
+                       );
+               }
+
                // @phan-suppress-next-line PhanUndeclaredMethod
                return $this->run( ...$params );
        }