diff options
author | Vitor Mattos <vitor@php.rio> | 2022-04-20 17:03:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 17:03:07 +0300 |
commit | db385cce6805ee1dfafd89804383233ae3868e3b (patch) | |
tree | 545887a457010b7a5a188695deb692b4af5f1991 /lib | |
parent | 9c0d9e29df08d2be50f5a89dcf01903136c18ca2 (diff) | |
parent | 8bd7f80c1177464c3ff36328e0691b81d9454ce4 (diff) |
Merge pull request #7172 from nextcloud/feature/move-command-listener-annonymous-function-to-static
Move command listener anonymous function to static
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Chat/Command/Listener.php | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/Chat/Command/Listener.php b/lib/Chat/Command/Listener.php index de7a56807..bbdda8eda 100644 --- a/lib/Chat/Command/Listener.php +++ b/lib/Chat/Command/Listener.php @@ -41,33 +41,35 @@ class Listener { } public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addListener(ChatManager::EVENT_BEFORE_MESSAGE_SEND, static function (ChatParticipantEvent $event) { - $message = $event->getComment(); - $participant = $event->getParticipant(); - - /** @var self $listener */ - $listener = \OC::$server->get(self::class); - - if (strpos($message->getMessage(), '//') === 0) { - return; - } - - try { - /** @var Command $command */ - /** @var string $arguments */ - [$command, $arguments] = $listener->getCommand($message->getMessage()); - $command = $listener->commandService->resolveAlias($command); - } catch (DoesNotExistException $e) { - return; - } - - if (!$listener->executor->isCommandAvailableForParticipant($command, $participant)) { - $command = $listener->commandService->find('', 'help'); - $arguments = trim($message->getMessage()); - } - - $listener->executor->exec($event->getRoom(), $message, $command, $arguments, $participant); - }); + $dispatcher->addListener(ChatManager::EVENT_BEFORE_MESSAGE_SEND, [self::class, 'executeCommand']); + } + + public static function executeCommand(ChatParticipantEvent $event): void { + $message = $event->getComment(); + $participant = $event->getParticipant(); + + /** @var self $listener */ + $listener = \OC::$server->get(self::class); + + if (strpos($message->getMessage(), '//') === 0) { + return; + } + + try { + /** @var Command $command */ + /** @var string $arguments */ + [$command, $arguments] = $listener->getCommand($message->getMessage()); + $command = $listener->commandService->resolveAlias($command); + } catch (DoesNotExistException $e) { + return; + } + + if (!$listener->executor->isCommandAvailableForParticipant($command, $participant)) { + $command = $listener->commandService->find('', 'help'); + $arguments = trim($message->getMessage()); + } + + $listener->executor->exec($event->getRoom(), $message, $command, $arguments, $participant); } /** |