api = $api; $this->coreIntegration = $coreIntegration; $this->wordPressIntegration = $wordPressIntegration; $this->registry = $registry; $this->stepHandler = $stepHandler; $this->triggerHandler = $triggerHandler; $this->wordPress = $wordPress; $this->automationStorage = $automationStorage; } public function initialize(): void { $this->registerApiRoutes(); $this->api->initialize(); $this->stepHandler->initialize(); $this->triggerHandler->initialize(); $this->coreIntegration->register($this->registry); $this->wordPressIntegration->register($this->registry); $this->wordPress->doAction(Hooks::INITIALIZE, [$this->registry]); $this->registerActiveTriggerHooks(); } private function registerApiRoutes(): void { $this->wordPress->addAction(Hooks::API_INITIALIZE, function (API $api) { $api->registerGetRoute('automations', AutomationsGetEndpoint::class); $api->registerPutRoute('automations/(?P\d+)', AutomationsPutEndpoint::class); $api->registerDeleteRoute('automations/(?P\d+)', AutomationsDeleteEndpoint::class); $api->registerPostRoute('automations/(?P\d+)/duplicate', AutomationsDuplicateEndpoint::class); $api->registerPostRoute('automations/create-from-template', AutomationsCreateFromTemplateEndpoint::class); $api->registerGetRoute('automation-templates', AutomationTemplatesGetEndpoint::class); $api->registerGetRoute('automation-templates/(?P.+)', AutomationTemplateGetEndpoint::class); }); } private function registerActiveTriggerHooks(): void { $triggerKeys = $this->automationStorage->getActiveTriggerKeys(); foreach ($triggerKeys as $triggerKey) { $instance = $this->registry->getTrigger($triggerKey); if ($instance) { $instance->registerHooks(); } } } }