register(); ( new SecurityBootstrap() )->register(); $this->registerEventBus(); $this->registerWorkflowEngine(); $this->registerEventListeners(); $this->registerAsyncEventDispatcher(); if ( is_admin() ) { ( new AdminBootstrap() )->register(); } $this->registerCartModule(); ( new WooCommerceBootstrap( $this->getAsyncDispatcher(), $this->getWorkflowEngine(), $this->abandoned_cart_service ) )->register(); $this->registerWorkflowScheduler(); $this->registerExecutionEngine(); $this->registerAsyncBootstrap(); } /** * Register EventBus. * * @return void */ private function registerEventBus(): void { $this->event_bus = new EventBus(); } /** * Register AsyncEventDispatcher and dependencies. * * @return void */ private function registerAsyncEventDispatcher(): void { $this->event_queue_repository = new EventQueueRepository(); $this->async_dispatcher = new AsyncEventDispatcher( $this->event_queue_repository ); } /** * Register async event processing (cron). * * @return void */ private function registerAsyncBootstrap(): void { ( new AsyncBootstrap( $this->getEventWorker() ) )->register(); } /** * Register WorkflowEngine and WorkflowQueue. * * @return void */ private function registerWorkflowEngine(): void { $this->workflow_engine = new WorkflowEngine(); } /** * Subscribe event listeners to EventBus. * * @return void */ private function registerEventListeners(): void { $listener = new WorkflowTriggerListener( $this->getWorkflowEngine(), $this->getWorkflowEngine()->getQueue() ); $this->getEventBus()->subscribe( $listener ); } /** * @var AbandonedCartService|null */ private ?AbandonedCartService $abandoned_cart_service = null; /** * Register abandoned cart module. * * @return void */ private function registerCartModule(): void { $this->abandoned_cart_service = new AbandonedCartService( null, $this->getAsyncDispatcher() ); $bootstrap = new CartBootstrap( $this->abandoned_cart_service ); $bootstrap->register(); } /** * Register workflow scheduler (cron). * * @return void */ private function registerWorkflowScheduler(): void { $queue = $this->getWorkflowEngine()->getQueue(); $scheduler = new WorkflowScheduler( $queue ); $scheduler->register(); } /** * Register the local execution engine and resume cron. * * @return void */ private function registerExecutionEngine(): void { ( new ExecutionBootstrap( $this->getExecutionEngine(), $this->getEventWorker(), $this->event_queue_repository, $this->getWorkflowEngine()->getQueue() ) )->register(); } /** * Get the event worker instance. * * @return EventWorker */ private function getEventWorker(): EventWorker { if ( null === $this->event_worker ) { $repository = $this->event_queue_repository ?? new EventQueueRepository(); $this->event_worker = new EventWorker( $repository, $this->getExecutionEngine() ); } return $this->event_worker; } /** * Get EventBus instance. * * @return EventBus */ public function getEventBus(): EventBus { if ( null === $this->event_bus ) { $this->event_bus = new EventBus(); } return $this->event_bus; } /** * Get WorkflowEngine instance. * * @return WorkflowEngine */ public function getWorkflowEngine(): WorkflowEngine { if ( null === $this->workflow_engine ) { $this->workflow_engine = new WorkflowEngine(); } return $this->workflow_engine; } /** * Get local execution engine instance. * * @return ExecutionEngine */ public function getExecutionEngine(): ExecutionEngine { if ( null === $this->execution_engine ) { $this->execution_engine = new ExecutionEngine( $this->getWorkflowEngine()->getQueue(), $this->getWorkflowEngine() ); } return $this->execution_engine; } /** * Get AsyncEventDispatcher instance. * * @return AsyncEventDispatcher */ public function getAsyncDispatcher(): AsyncEventDispatcher { if ( null === $this->async_dispatcher ) { $this->event_queue_repository = new EventQueueRepository(); $this->async_dispatcher = new AsyncEventDispatcher( $this->event_queue_repository ); } return $this->async_dispatcher; } }