Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.63 KB

File metadata and controls

56 lines (37 loc) · 1.63 KB

Channels And Drivers

A channel is a normalized name mapped to a NotificationDriverInterface implementation.

Channel Registry

use CommonPHP\Notifications\ChannelRegistry;

$channels = ChannelRegistry::single('email', $emailDriver)
    ->register('sms', $smsDriver)
    ->register('webhook', $webhookDriver);

The first registered channel becomes the default unless another channel is registered or set as default.

$channels->setDefault('sms');
$driver = $channels->get();

Notifier Channel Management

$notifier
    ->registerChannel('email', $emailDriver)
    ->useChannel('sms', $smsDriver, default: true)
    ->useDefaultChannel('email');

registerChannel() rejects duplicate channel names. useChannel() replaces or creates a channel.

Driver Contract

Drivers implement:

use CommonPHP\Notifications\Contracts\NotificationDriverInterface;

interface NotificationDriverInterface
{
    public function getName(): string;

    public function supports(Notification $notification, string $channel): bool;

    public function send(Notification $notification, string $channel): DeliveryResult;
}

Use AbstractNotificationDriver when implementing a custom driver. It provides a default getName(), a default permissive supports(), recipient filtering, and helper methods for sent, queued, skipped, and failed results.

Built-In Drivers

ArrayNotificationDriver records successful deliveries in memory. It is useful for tests and local development.

NullNotificationDriver returns a skipped delivery result and does not store anything. It is useful when notifications are intentionally disabled.