/** * Register a Zikula_AbstractEventHandler as a persistent handler. * * @param string $moduleName Module name. * @param string $className Class name (subclass of Zikula_AbstractEventHandler). * * @throws InvalidArgumentException If class is not available or not a subclass of Zikula_AbstractEventHandler. * * @return void * * Note: If the exact same handler is already registered, this function does nothing. */ public static function registerPersistentEventHandlerClass($moduleName, $className) { if (!class_exists($className)) { throw new InvalidArgumentException(sprintf('Class %s does not exist or cannot be found', $className)); } $reflection = new ReflectionClass($className); if (!$reflection->isSubclassOf('Zikula_AbstractEventHandler')) { throw new InvalidArgumentException(sprintf('%s is not a subclass of Zikula_AbstractEventHandler', $className)); } $handlers = ModUtil::getVar(self::HANDLERS, $moduleName, array()); $newHandler = array('classname' => $className); foreach ($handlers as $handler) { if ($handler == $newHandler) { // The exact same handler exists already. Do nothing but display a warning. if (System::isDevelopmentMode()) { LogUtil::registerWarning(__f('The eventhandler class "%1$s" for "%2$s" could not be registered because it is registered already.', array($className, $moduleName))); } else { $warns = LogUtil::getWarningMessages(false); $msg = __f('The eventhandlers for "%1$s" could not be registered because they are registered already.', array($moduleName)); if (!in_array(DataUtil::formatForDisplayHTML($msg), $warns)) { LogUtil::registerWarning($msg); } } return; } } $handlers[] = $newHandler; ModUtil::setVar(self::HANDLERS, $moduleName, $handlers); }