dida / eventbus
A lightweight PHP Event Bus library.
v1.0.0
2021-12-24 10:05 UTC
Requires
- php: ^7.1
This package is auto-updated.
Last update: 2024-03-27 11:24:15 UTC
README
A lightweight PHP Event Bus library for Dida Framework.
API
public static function addEvent(string $event):void;
public static function removeEvent(string $event):void;
public static function hasEvent(string $event):bool
public static function hook(string $event, callable $callback, array $parameters = [], ?string $callback_id = null);
public static function unhook(string $event, ?string $callback_id = null):void;
public static function trigger(string $event):void;
Code
use Dida\EventBus;
// Add an event.
EventBus::addEvent("YOUR.EVENT");
// Hook some callbacks.
...
EventBus::hook("YOUR.EVENT", your_callback_1, [param1, param2, ...]);
...
EventBus::hook("YOUR.EVENT", your_callback_2, [param1, param2, ...]);
...
EventBus::hook("YOUR.EVENT", your_callback_3, [param1, param2, ...]);
// Trigger an event and execute all hooked callbacks.
EventBus::trigger("YOUR.EVENT");