39 lines
1008 B
PHP
Executable File
39 lines
1008 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use CodeIgniter\Events\Events;
|
|
|
|
class NotificationService
|
|
{
|
|
/**
|
|
* Trigger a notification event by type and payload.
|
|
*
|
|
* @param string $eventType The name of the event (e.g., 'userRegistered')
|
|
* @param array $payload The data to pass to the listener
|
|
* @return void
|
|
*/
|
|
public static function trigger(string $eventType, array $payload): void
|
|
{
|
|
Events::trigger($eventType, $payload);
|
|
}
|
|
|
|
/**
|
|
* Helper for sending to a specific user.
|
|
*
|
|
* @param int $userId
|
|
* @param string $title
|
|
* @param string $message
|
|
* @param array $channels
|
|
* @return void
|
|
*/
|
|
public static function toUser(int $userId, string $title, string $message, array $channels = ['in_app']): void
|
|
{
|
|
self::trigger('customNotification', [
|
|
'user_id' => $userId,
|
|
'title' => $title,
|
|
'message' => $message,
|
|
'channels' => $channels
|
|
]);
|
|
}
|
|
} |