Skip to content
docsv0.1.0

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

Parameters of __construct()
NameTypeDescription
$logger?Psr\Log\LoggerInterface

NotificationDispatcher::addChannel()

public function addChannel(Milpa\Notifications\Contracts\NotificationChannelInterface $channel): self

Register a notification channel.

Parameters

Parameters of addChannel()
NameTypeDescription
$channelMilpa\Notifications\Contracts\NotificationChannelInterface

NotificationDispatcher::removeChannel()

public function removeChannel(string $channelName): self

Remove a channel by name.

Parameters

Parameters of removeChannel()
NameTypeDescription
$channelNamestring

NotificationDispatcher::getChannels()

public function getChannels(): array

Get all registered channels.

NotificationDispatcher::hasChannel()

public function hasChannel(string $channelName): bool

Check if a channel is registered.

Parameters

Parameters of hasChannel()
NameTypeDescription
$channelNamestring

NotificationDispatcher::dispatch()

public function dispatch(Milpa\Notifications\Contracts\NotificationPayloadInterface $payload, array $recipients): array

Dispatch a notification to specific recipients. Recipients format: "channel:recipient_id" Example: ["telegram:123456", "pusher:room1", "websocket:user:42"]

Parameters

Parameters of dispatch()
NameTypeDescription
$payloadNotificationPayloadInterfaceThe notification data
$recipientsstring[]Array of "channel:recipient" strings

Returns

Results per recipient

NotificationDispatcher::broadcast()

public function broadcast(Milpa\Notifications\Contracts\NotificationPayloadInterface $payload, string $recipientId): array

Broadcast a notification to all channels.

Parameters

Parameters of broadcast()
NameTypeDescription
$payloadNotificationPayloadInterfaceThe notification data
$recipientIdstringThe recipient ID (same for all channels)

Returns

Results per channel