Skip to main content
Aikeedo dispatches domain events whenever something meaningful happens: a user signs up, an order is fulfilled, credits are consumed. Plugins subscribe to those events, and use the cron event for scheduled work.

Subscribe to an event

Register listeners in boot() through the event mapper:
src/Plugin.php

Write a listener

A listener is an invokable class. It’s resolved from the container, so it can depend on any service:
src/Listeners/PushContact.php
Listeners run synchronously inside the request that dispatched the event. Keep them fast, and catch your own exceptions, or a failing third-party API will break signup. Log failures instead of swallowing them silently, and reconcile later from cron.

Priorities

Priority::HIGH (100) runs before Priority::NORMAL (50), which runs before Priority::LOW (0).

Inheritance matters

Listeners match with instanceof, so a listener on a parent class also receives its subclasses.
Registering the same listener on both UserUpdatedEvent and EmailVerifiedEvent makes it run twice when an email is verified. Subscribe to the most general event you care about, and branch inside the listener with instanceof if you need to tell them apart.

Events you can subscribe to

Class names are under <Module>\Domain\Events\. See the event catalog for the full list, including who listens in core.

Dispatch your own events

Other plugins can then subscribe to your event, which is how you make your plugin extensible.

Scheduled work

There’s no queue. Recurring work runs when cron.php executes, which dispatches Cron\Domain\Events\CronEvent. Subscribe to it like any other event.
A cron listener should process a bounded batch and remember where it stopped, because the next tick may be a minute away:
src/Listeners/SyncContacts.php
Points to copy from this pattern:
  • Opt in. Do nothing unless an administrator started the job, so an idle installation pays nothing for your plugin.
  • Batch. Process a fixed number of records per tick.
  • Persist a cursor. Store the last processed ID in an option, so the next tick continues instead of restarting.
  • Track counters and a status. processing, paused and completed give the admin page something to show, and stopping is just a status change.
  • Rate-limit yourself. For a daily job, store a timestamp and return early until it’s due.
Entity changes made in cron listeners are flushed after the event finishes, the same as in a web request.

Testing

  • Run the cron tick by hand with php cron.php.
  • Trigger domain events by doing the thing in the UI, such as creating a user.
  • Watch var/log/app-*.log, and log at the start and end of your listener while developing.