From 3aceed93171132fe7c33bf939a643ada14052ab1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 10 Mar 2024 15:19:02 +0100 Subject: [PATCH] Hydrate the parameters using a readonly struct --- ...ditorGetMentionSuggestionsAction.class.php | 7 +++---- .../messages/MentionSuggestions.class.php | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php b/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php index ffdd20b6bc..5f04b4a6d6 100644 --- a/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php +++ b/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php @@ -7,7 +7,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use wcf\http\Helper; use wcf\system\endpoint\controller\core\messages\MentionSuggestions; -use wcf\system\endpoint\Parameters; /** * Suggests users that may be mentioned. @@ -29,13 +28,13 @@ final class EditorGetMentionSuggestionsAction implements RequestHandlerInterface \assert(\count($parameters) === 1); \assert($parameters[0]->getName() === 'parameters'); - $attribute = current($parameters[0]->getAttributes(Parameters::class)); + $type = $parameters[0]->getType(); - \assert($attribute !== false); + \assert($type instanceof \ReflectionNamedType); $parameters = Helper::mapQueryParameters( $request->getQueryParams(), - $attribute->newInstance()->arrayShape, + $type->getName(), ); return (new MentionSuggestions())->mentionSuggestions($parameters); diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/MentionSuggestions.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/MentionSuggestions.class.php index af17c295fd..1ed792b5f9 100644 --- a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/MentionSuggestions.class.php +++ b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/MentionSuggestions.class.php @@ -15,16 +15,9 @@ final class MentionSuggestions implements IController { #[GetRequest('/core/messages/mentionsuggestions')] public function mentionSuggestions( - #[Parameters( - <<<'EOT' - array { - query: non-empty-string - } - EOT, - )] - array $parameters + #[Parameters] MentionSuggestionsParameters $parameters ): ResponseInterface { - $query = \mb_strtolower($parameters['query']); + $query = \mb_strtolower($parameters->query); $matches = []; foreach ($this->getGroups($query) as $userGroup) { @@ -92,3 +85,13 @@ final class MentionSuggestions implements IController return $userGroups; } } + +/** @internal */ +final class MentionSuggestionsParameters +{ + public function __construct( + /** @var non-empty-string */ + public readonly string $query, + ) { + } +} -- 2.20.1