NotificationDispatcher
Dispatches notifications to multiple channels. Acts as a notification hub that can send the same notification to multiple registered channels (Telegram, Pusher, WebSocket, etc).
NotificationDispatcher::__construct()
public function __construct(?Psr\Log\LoggerInterface $logger = null):Parameters
| Name | Type | Description |
|---|---|---|
| $logger | ?Psr\Log\LoggerInterface |
NotificationDispatcher::addChannel()
public function addChannel(Milpa\Notifications\Contracts\NotificationChannelInterface $channel): selfRegister a notification channel.
Parameters
| Name | Type | Description |
|---|---|---|
| $channel | Milpa\Notifications\Contracts\NotificationChannelInterface |
NotificationDispatcher::removeChannel()
public function removeChannel(string $channelName): selfRemove a channel by name.
Parameters
| Name | Type | Description |
|---|---|---|
| $channelName | string |
NotificationDispatcher::getChannels()
public function getChannels(): arrayGet all registered channels.
NotificationDispatcher::hasChannel()
public function hasChannel(string $channelName): boolCheck if a channel is registered.
Parameters
| Name | Type | Description |
|---|---|---|
| $channelName | string |
NotificationDispatcher::dispatch()
public function dispatch(Milpa\Notifications\Contracts\NotificationPayloadInterface $payload, array $recipients): arrayDispatch a notification to specific recipients. Recipients format: "channel:recipient_id" Example: ["telegram:123456", "pusher:room1", "websocket:user:42"]
Parameters
| Name | Type | Description |
|---|---|---|
| $payload | NotificationPayloadInterface | The notification data |
| $recipients | string[] | Array of "channel:recipient" strings |
Returns
Results per recipient
NotificationDispatcher::broadcast()
public function broadcast(Milpa\Notifications\Contracts\NotificationPayloadInterface $payload, string $recipientId): arrayBroadcast a notification to all channels.
Parameters
| Name | Type | Description |
|---|---|---|
| $payload | NotificationPayloadInterface | The notification data |
| $recipientId | string | The recipient ID (same for all channels) |
Returns
Results per channel