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 ac0c6c6 commit c02630a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/InvoicesModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}

Expand Down

0 comments on commit c02630a

Please sign in to comment.