Skip to content

Commit

Permalink
Add lazy event listener registration
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Matus Kalafut committed Sep 27, 2023
1 parent c698c33 commit d419bb2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/RempMailerModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}

Expand Down

0 comments on commit d419bb2

Please sign in to comment.