Use `Helper::mapQueryParameters()` in `StyleAddDarkModeAction`
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 9 Mar 2023 14:22:58 +0000 (15:22 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 9 Mar 2023 14:22:58 +0000 (15:22 +0100)
wcfsetup/install/files/lib/acp/action/StyleAddDarkModeAction.class.php

index 287350dc065bffb7691b6192b6d3d99c96a03042..689eb91f2695a782c69bddb31e4eeebe57ea940f 100644 (file)
@@ -11,6 +11,7 @@ use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Server\RequestHandlerInterface;
 use wcf\data\style\Style;
+use wcf\http\Helper;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\style\command\AddDarkMode;
@@ -27,30 +28,18 @@ use wcf\system\WCF;
  */
 final class StyleAddDarkModeAction implements RequestHandlerInterface
 {
-    private const PARAMETERS = <<<'EOT'
-        array {
-            id: positive-int
-        }
-        EOT;
-
-    private readonly TreeMapper $mapper;
-
-    public function __construct()
-    {
-        $this->mapper = (new MapperBuilder())
-            ->allowSuperfluousKeys()
-            ->enableFlexibleCasting()
-            ->mapper();
-    }
-
     /**
      * @inheritDoc
      */
     public function handle(ServerRequestInterface $request): ResponseInterface
     {
-        $parameters = $this->mapper->map(
-            self::PARAMETERS,
-            Source::array($request->getQueryParams())
+        $parameters = Helper::mapQueryParameters(
+            $request->getQueryParams(),
+            <<<'EOT'
+                array {
+                    id: positive-int
+                }
+                EOT,
         );
 
         $style = new Style($parameters['id']);