<?php
 class vB_Library { use vB_Trait_NoSerialize; protected static $instance = []; protected function __construct() {} public static function instance($tag = '') : static { if ($tag) { $className = self::getLibraryClassNameInternal($tag); } else { $className = get_called_class(); } return self::$instance[strtolower($className)] ??= new $className(); } protected static function getLibraryClassNameInternal($controller) : string { $values = explode(':', $controller); $package = ''; if (count($values) == 1) { $c = 'vB_Library_' . ucfirst(strtolower($controller)); } else { [$package, $controller] = $values; $package = strtolower($package); $c = ucfirst($package) . '_Library_' . ucfirst(strtolower($controller)); $products = vB::getDatastore()->getValue('products'); if (empty($products[$package])) { throw new vB_Exception_Api('cant_load_product_x_disabled', [$controller, $package]); } } return $c; } public static function getContentInstance($contenttypeid) { $contentType = vB_Types::instance()->getContentClassFromId($contenttypeid); $className = 'Content_' . $contentType['class']; return self::instance($className); } public static function clearCache() { self::$instance = []; } public function monitorWords($text, $type, $nodeid, $userid = null, $insertNotifications = true, $currentuserid = 0) { $notificationLib = vB_Library_Notification::instance('notification'); if (!$currentuserid) { $currentuserid = vB::getCurrentSession()->get('userid'); } [$mainType, $subType] = explode('-', $type, 2); switch ($mainType) { case 'node': $notificationLib->triggerNodeWordNotificationEvent($subType, $text, $nodeid, $currentuserid); break; case 'user': $notificationLib->triggerUserWordNotificationEvent($subType, $text, $userid, $currentuserid); break; } if ($insertNotifications) { $notificationLib->insertNotificationsToDB(); } } } 