From c02630aadfe55173bfb41459c84f3e68d85d7bec 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/InvoicesModule.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/InvoicesModule.php b/src/InvoicesModule.php index 200de93..636fb14 100644 --- a/src/InvoicesModule.php +++ b/src/InvoicesModule.php @@ -15,7 +15,6 @@ use Crm\InvoicesModule\Seeders\AddressTypesSeeder; use Crm\InvoicesModule\Seeders\ConfigsSeeder; use Crm\InvoicesModule\Seeders\PaymentGatewaysSeeder; -use League\Event\Emitter; use Tomaj\Hermes\Dispatcher; class InvoicesModule extends CrmModule @@ -103,27 +102,27 @@ public function registerSeeders(SeederManager $seederManager) $seederManager->addSeeder($this->getInstance(PaymentGatewaysSeeder::class)); } - public function registerEventHandlers(Emitter $emitter) + public function registerLazyEventHandlers(\Crm\ApplicationModule\Event\LazyEventEmitter $emitter) { $emitter->addListener( \Crm\UsersModule\Events\AddressChangedEvent::class, - $this->getInstance(\Crm\InvoicesModule\Events\AddressChangedHandler::class) + \Crm\InvoicesModule\Events\AddressChangedHandler::class ); $emitter->addListener( \Crm\UsersModule\Events\AddressRemovedEvent::class, - $this->getInstance(\Crm\InvoicesModule\Events\AddressRemovedHandler::class) + \Crm\InvoicesModule\Events\AddressRemovedHandler::class ); $emitter->addListener( \Crm\UsersModule\Events\PreNotificationEvent::class, - $this->getInstance(\Crm\InvoicesModule\Events\PreNotificationEventHandler::class) + \Crm\InvoicesModule\Events\PreNotificationEventHandler::class ); $emitter->addListener( \Crm\UsersModule\Events\NewAddressEvent::class, - $this->getInstance(\Crm\InvoicesModule\Events\NewAddressHandler::class) + \Crm\InvoicesModule\Events\NewAddressHandler::class ); $emitter->addListener( \Crm\PaymentsModule\Events\PaymentChangeStatusEvent::class, - $this->getInstance(\Crm\InvoicesModule\Events\PaymentStatusChangeHandler::class) + \Crm\InvoicesModule\Events\PaymentStatusChangeHandler::class ); }