Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.11 KB

File metadata and controls

42 lines (29 loc) · 1.11 KB

Service Provider

NotificationsServiceProvider integrates the package with CommonPHP Runtime and PHP-DI.

Registered Definitions

The provider registers:

  • ArrayNotificationDriver
  • NotificationDriverInterface
  • ChannelRegistry
  • Notifier
  • NotifierInterface

The default binding uses ArrayNotificationDriver on the default channel. Applications should override these definitions or replace channels when wiring real provider drivers.

Runtime Usage

use CommonPHP\Notifications\NotificationsServiceProvider;
use CommonPHP\Runtime\Kernel;

$kernel = new Kernel();
$kernel->useServiceProvider(new NotificationsServiceProvider());

Once configured, application services can depend on NotifierInterface.

use CommonPHP\Notifications\Contracts\NotifierInterface;

final readonly class WelcomeUser
{
    public function __construct(private NotifierInterface $notifications)
    {
    }
}

Replacing Drivers

Provider packages can expose their own service provider and bind NotificationDriverInterface, or application setup can fetch Notifier and register named channels explicitly.