[] */ protected array $handlers = []; public function handle(string $activityType, string|Loggable $detail): void { $handlersToRun = $this->handlers[$activityType] ?? []; foreach ($handlersToRun as $handlerClass) { /** @var NotificationHandler $handler */ $handler = app()->make($handlerClass); $handler->handle($activityType, $detail); } } /** * @param class-string $handlerClass */ public function registerHandler(string $activityType, string $handlerClass): void { if (!isset($this->handlers[$activityType])) { $this->handlers[$activityType] = []; } if (!in_array($handlerClass, $this->handlers[$activityType])) { $this->handlers[$activityType][] = $handlerClass; } } public function loadDefaultHandlers(): void { $this->registerHandler(ActivityType::PAGE_CREATE, PageCreationNotificationHandler::class); $this->registerHandler(ActivityType::PAGE_UPDATE, PageUpdateNotificationHandler::class); $this->registerHandler(ActivityType::COMMENT_CREATE, CommentCreationNotificationHandler::class); } }