Rename the controller
authorAlexander Ebert <ebert@woltlab.com>
Tue, 19 Mar 2024 15:27:17 +0000 (16:27 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 19 Mar 2024 15:27:17 +0000 (16:27 +0100)
wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php
wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php
wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMentionSuggestions.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/endpoint/controller/core/messages/MentionSuggestions.class.php [deleted file]

index a6e401cdea445988aa523102d6a1d8724f9f3059..11f97c3e4e28ba00b11907847d3e3f5c14ca22fd 100644 (file)
@@ -5,7 +5,7 @@ namespace wcf\action;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Server\RequestHandlerInterface;
-use wcf\system\endpoint\controller\core\messages\MentionSuggestions;
+use wcf\system\endpoint\controller\core\messages\GetMentionSuggestions;
 
 /**
  * Suggests users that may be mentioned.
@@ -20,7 +20,7 @@ final class EditorGetMentionSuggestionsAction implements RequestHandlerInterface
 {
     public function handle(ServerRequestInterface $request): ResponseInterface
     {
-        $controller = new MentionSuggestions();
+        $controller = new GetMentionSuggestions();
 
         return $controller($request, []);
     }
index 3f6fb50bbb9f776bd5bedcefce701521c61fe9ef..1711b94975568bc5a64045e85b97574e4bd9f7c5 100644 (file)
@@ -85,7 +85,7 @@ return static function (): void {
     });
 
     $eventHandler->register(ControllerCollecting::class, static function (ControllerCollecting $event) {
-        $event->register(new \wcf\system\endpoint\controller\core\messages\MentionSuggestions);
+        $event->register(new \wcf\system\endpoint\controller\core\messages\GetMentionSuggestions);
         $event->register(new \wcf\system\endpoint\controller\core\sessions\DeleteSession);
     });
 
diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMentionSuggestions.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/messages/GetMentionSuggestions.class.php
new file mode 100644 (file)
index 0000000..d16045a
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+
+namespace wcf\system\endpoint\controller\core\messages;
+
+use Laminas\Diactoros\Response\JsonResponse;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use wcf\data\user\group\UserGroup;
+use wcf\data\user\UserProfileList;
+use wcf\http\Helper;
+use wcf\system\endpoint\GetRequest;
+use wcf\system\endpoint\IController;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+
+/**
+ * Retrieves the list of users and groups that can be mentioned.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+#[GetRequest('/core/messages/mentionsuggestions')]
+final class GetMentionSuggestions implements IController
+{
+    #[\Override]
+    public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
+    {
+        $parameters = Helper::mapApiParameters($request, GetMentionSuggestionsParameters::class);
+        if (\mb_strlen($parameters->query) < 3) {
+            throw new UserInputException('query', 'tooShort');
+        }
+
+        $query = \mb_strtolower($parameters->query);
+        $matches = [];
+
+        foreach ($this->getGroups($query) as $userGroup) {
+            $matches[] = [
+                'name' => $userGroup->getName(),
+                'groupID' => $userGroup->groupID,
+                'type' => 'group',
+            ];
+        }
+
+        foreach ($this->getUsers($query) as $userProfile) {
+            $matches[] = [
+                'avatarTag' => $userProfile->getAvatar()->getImageTag(16),
+                'username' => $userProfile->getUsername(),
+                'userID' => $userProfile->getObjectID(),
+                'type' => 'user',
+            ];
+        }
+
+        return new JsonResponse(
+            $matches,
+            200,
+            [
+                'cache-control' => [
+                    'max-age=300',
+                ],
+            ]
+        );
+    }
+
+    /**
+     * @return list<UserProfile>
+     */
+    private function getUsers(string $query): array
+    {
+        $userProfileList = new UserProfileList();
+        $userProfileList->getConditionBuilder()->add("username LIKE ?", [$query . '%']);
+
+        $userProfileList->sqlLimit = 10;
+        $userProfileList->readObjects();
+
+        return \array_values($userProfileList->getObjects());
+    }
+
+    /**
+     * @return list<UserGroup>
+     */
+    private function getGroups(string $query): array
+    {
+        $userGroups = UserGroup::getMentionableGroups();
+        if ($userGroups === []) {
+            return [];
+        }
+
+        $userGroups = \array_filter($userGroups, static function (UserGroup $userGroup) use ($query) {
+            return \str_starts_with(\mb_strtolower($userGroup->getName()), $query);
+        });
+
+        $collator = new \Collator(WCF::getLanguage()->getLocale());
+        \usort(
+            $userGroups,
+            static fn (UserGroup $a, UserGroup $b) => $collator->compare($a->getName(), $b->getName())
+        );
+
+        return $userGroups;
+    }
+}
+
+/** @internal */
+final class GetMentionSuggestionsParameters
+{
+    public function __construct(
+        /** @var non-empty-string */
+        public readonly string $query,
+    ) {
+    }
+}
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
deleted file mode 100644 (file)
index ea3d267..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-
-namespace wcf\system\endpoint\controller\core\messages;
-
-use Laminas\Diactoros\Response\JsonResponse;
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
-use wcf\data\user\group\UserGroup;
-use wcf\data\user\UserProfileList;
-use wcf\http\Helper;
-use wcf\system\endpoint\GetRequest;
-use wcf\system\endpoint\IController;
-use wcf\system\exception\UserInputException;
-use wcf\system\WCF;
-
-/**
- * Retrieves the list of users and groups that can be mentioned.
- *
- * @author Alexander Ebert
- * @copyright 2001-2024 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @since 6.1
- */
-#[GetRequest('/core/messages/mentionsuggestions')]
-final class MentionSuggestions implements IController
-{
-    #[\Override]
-    public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface
-    {
-        $parameters = Helper::mapApiParameters($request, MentionSuggestionsParameters::class);
-        if (\mb_strlen($parameters->query) < 3) {
-            throw new UserInputException('query', 'tooShort');
-        }
-
-        $query = \mb_strtolower($parameters->query);
-        $matches = [];
-
-        foreach ($this->getGroups($query) as $userGroup) {
-            $matches[] = [
-                'name' => $userGroup->getName(),
-                'groupID' => $userGroup->groupID,
-                'type' => 'group',
-            ];
-        }
-
-        foreach ($this->getUsers($query) as $userProfile) {
-            $matches[] = [
-                'avatarTag' => $userProfile->getAvatar()->getImageTag(16),
-                'username' => $userProfile->getUsername(),
-                'userID' => $userProfile->getObjectID(),
-                'type' => 'user',
-            ];
-        }
-
-        return new JsonResponse(
-            $matches,
-            200,
-            [
-                'cache-control' => [
-                    'max-age=300',
-                ],
-            ]
-        );
-    }
-
-    /**
-     * @return list<UserProfile>
-     */
-    private function getUsers(string $query): array
-    {
-        $userProfileList = new UserProfileList();
-        $userProfileList->getConditionBuilder()->add("username LIKE ?", [$query . '%']);
-
-        $userProfileList->sqlLimit = 10;
-        $userProfileList->readObjects();
-
-        return \array_values($userProfileList->getObjects());
-    }
-
-    /**
-     * @return list<UserGroup>
-     */
-    private function getGroups(string $query): array
-    {
-        $userGroups = UserGroup::getMentionableGroups();
-        if ($userGroups === []) {
-            return [];
-        }
-
-        $userGroups = \array_filter($userGroups, static function (UserGroup $userGroup) use ($query) {
-            return \str_starts_with(\mb_strtolower($userGroup->getName()), $query);
-        });
-
-        $collator = new \Collator(WCF::getLanguage()->getLocale());
-        \usort(
-            $userGroups,
-            static fn (UserGroup $a, UserGroup $b) => $collator->compare($a->getName(), $b->getName())
-        );
-
-        return $userGroups;
-    }
-}
-
-/** @internal */
-final class MentionSuggestionsParameters
-{
-    public function __construct(
-        /** @var non-empty-string */
-        public readonly string $query,
-    ) {
-    }
-}