From d419bb2dc1728b1520c39918871e7ebde4b074c9 Mon Sep 17 00:00:00 2001 From: Matus Kalafut Date: Wed, 27 Sep 2023 09:19:55 +0000 Subject: [PATCH] Add lazy event listener registration - Add `LazyEventEmitter` which extends `League\Event\Emitter`. - Use new `TransformToLazyEventListeners` rector rule to transform event listeners registration to lazy variant in your own modules. - Change the registration of events in modules to use `LazyEventEmitter`. remp/crm#2116 --- src/RempMailerModule.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/RempMailerModule.php b/src/RempMailerModule.php index d6c0395..d47a9bf 100644 --- a/src/RempMailerModule.php +++ b/src/RempMailerModule.php @@ -17,7 +17,6 @@ use Crm\RempMailerModule\Components\MailLogs\MailLogs; use Crm\RempMailerModule\Components\UserEmailSettings\UserEmailSettingsWidget; use Crm\RempMailerModule\Seeders\SegmentsSeeder; -use League\Event\Emitter; use Tomaj\Hermes\Dispatcher; class RempMailerModule extends CrmModule @@ -27,27 +26,27 @@ public function registerUserData(UserDataRegistrator $dataRegistrator) $dataRegistrator->addUserDataProvider($this->getInstance(\Crm\RempMailerModule\Models\User\RempMailerUserDataProvider::class)); } - public function registerEventHandlers(Emitter $emitter) + public function registerLazyEventHandlers(\Crm\ApplicationModule\Event\LazyEventEmitter $emitter) { $emitter->addListener( \Crm\UsersModule\Events\UserRegisteredEvent::class, - $this->getInstance(\Crm\RempMailerModule\Events\SendWelcomeEmailHandler::class) + \Crm\RempMailerModule\Events\SendWelcomeEmailHandler::class ); // generic notifications $emitter->addListener( \Crm\UsersModule\Events\NotificationEvent::class, - $this->getInstance(\Crm\RempMailerModule\Events\NotificationHandler::class) + \Crm\RempMailerModule\Events\NotificationHandler::class ); $emitter->addListener( \Crm\RempMailerModule\Events\UserMailSubscriptionsChanged::class, - $this->getInstance(\Crm\RempMailerModule\Events\UserMailSubscriptionsChangedHandler::class) + \Crm\RempMailerModule\Events\UserMailSubscriptionsChangedHandler::class ); $emitter->addListener( \Crm\RempMailerModule\Events\ChangeUserNewsletterSubscriptionsEvent::class, - $this->getInstance(\Crm\RempMailerModule\Events\ChangeUserNewsletterSubscriptionsEventHandler::class) + \Crm\RempMailerModule\Events\ChangeUserNewsletterSubscriptionsEventHandler::class ); }