18 private static string $key =
'events/events';
28 self::$managedEvents[$eventName][] = $action;
34 public static function start():void {
36 self::$managedEvents = CacheManager::$cache->fetch(self::$key);
46 public static function addListener($eventNames, $action):void {
47 if (\is_array($eventNames)) {
48 foreach ($eventNames as $eventName) {
49 self::addOneListener($eventName, $action);
52 self::addOneListener($eventNames, $action);
61 foreach ($listeners as $eventName => $action) {
62 self::addOneListener($eventName, $action);
69 public static function store():void {
70 CacheManager::$cache->store(self::$key, self::$managedEvents);
78 public static function trigger(
string $eventName, &...$params):void {
79 if (isset(self::$managedEvents[$eventName])) {
80 foreach (self::$managedEvents[$eventName] as $action) {
81 self::triggerOne($action, $params);
86 private static function triggerOne($action, &$params):void {
87 if (\is_callable($action)) {
88 \call_user_func_array($action, $params);
89 } elseif (is_subclass_of($action, EventListenerInterface::class)) {
90 \call_user_func_array([
Manager for caches (Router, Rest, models).
static start()
Starts the event manager (in app/config/services.php)
static addListeners(array $listeners)
Adds a list of listeners.
static addOneListener(string $eventName, $action)
static store()
Store the managed events in cache (do not use in prod)
static addListener($eventNames, $action)
Adds a listener on eventName.
static triggerOne($action, &$params)
static trigger(string $eventName, &... $params)
Trigger an event.