Triangle Events registers application event listeners during Engine startup and provides an in-process dispatcher with exact-name and prefix listeners.
- PHP 8.1 or later
- Triangle Engine 9.x
Install the package with Composer:
composer require triangle/events:^2.0use support\Events;
Events::on('invoice.created', static function (array $invoice, string $event): void {
// Handle the created invoice.
});
Events::emit('invoice.created', ['id' => 42]);Use a trailing * to register a prefix listener, for example invoice.*. Listeners receive the event payload followed by the event name. Dispatch is process-local; it does not provide durable queueing or cross-worker delivery.
Listeners can also be declared in config/event.php:
return [
'invoice.created' => [
[App\Listeners\InvoiceCreated::class, 'handle'],
],
];The Engine bootstrap loads application and plugin event configuration at startup. Engine 8 is not supported: this component uses the plugin configuration hooks introduced in Engine 9.
Русская версия: README.ru.md.