From 8bd7f80c1177464c3ff36328e0691b81d9454ce4 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 19 Apr 2022 11:33:49 -0300 Subject: Move command listener annonymous function to static Signed-off-by: Vitor Mattos --- lib/Chat/Command/Listener.php | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'lib') 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); } /** -- cgit v1.2.3