Add helper method to get a comment manager by id
authorMarcel Werk <burntime@woltlab.com>
Fri, 14 Jun 2024 10:56:19 +0000 (12:56 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 14 Jun 2024 10:56:19 +0000 (12:56 +0200)
wcfsetup/install/files/lib/system/comment/CommentHandler.class.php

index a0eefc2c50c923dc820649e31c0796061afe8e10..dc6a9377be1a796a6420fb0e90e70b4aa229b14b 100644 (file)
@@ -96,6 +96,25 @@ class CommentHandler extends SingletonFactory
         return $this->getObjectType($objectTypeID)->getProcessor();
     }
 
+    /**
+     * Returns comment manager object for given object type id.
+     *
+     * @throws  \InvalidArgumentException
+     * @since   6.1
+     */
+    public function getCommentManagerByID(int $objectTypeID): ICommentManager
+    {
+        $objectType = $this->getObjectType($objectTypeID);
+        if ($objectType === null) {
+            throw new \InvalidArgumentException('unknown object type id given');
+        }
+
+        $processor = $objectType->getProcessor();
+        assert($processor instanceof ICommentManager);
+
+        return $processor;
+    }
+
     /**
      * Returns a comment list for a given object type and object id.
      *