perform/notification-bundle

Send notifications using a variety of publishers.

Installs: 1 334

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Type:symfony-bundle

dev-master 2019-06-15 11:04 UTC

This package is auto-updated.

Last update: 2024-03-28 00:59:12 UTC


README

Bundle for sending notifications to users in an application using a variety of publishers.

Usage

The perform_notification.notifier service is used to send notifications.

Create an instance of Perform\NotificationBundle\Notification, then use the Perform\NotificationBundle\Notifier\Notifier to send it.

Notification is an immutable value object that requires an array of recipients (implementing Perform\NotificationBundle\RecipientInterface), the notification type, and any context variables relevant to the notification type.

You can specify the publishers to use, or leave empty to use the default publishers.

//send using the default publishers
$notification = new Notification($recipient, 'test', ['context' => 'some_context_variable']);
$notifier->send($notification);
//send using the local and logger publishers
$notification = new Notification($recipient, 'test', ['context' => 'some_context_variable']);
$notifier->send($notification, ['local', 'logger]);
//send to multiple recipients
$notification = new Notification([$recipient, $recipient2], 'test', ['context' => 'some_context_variable']);
$notifier->send($notification, ['local', 'logger]);

Templates

Some publishers render notifications using twig, with the context variables passed in. Additionally, the following variables are set automatically:

  • currentRecipient - The identifier of the recipient for this message (a notification may be sent to many recipients).
  • notification - The notification object.

Each publisher looks for a template in PerformNotificationBundle:<type>:<publisher>.html.twig.

For example, sending a notification with type 'new_task', using the 'local' publisher, will render PerformNotificationBundle:new_task:local.html.twig.

To add a template without modifying this bundle, place them in app/Resources/PerformNotificationBundle/views.

e.g. PerformNotificationBundle:new_task:local.html.twig -> app/Resources/PerformNotificationBundle/views/new_task/local.html.twig.

Adding a notification publisher

Implement Perform\NotificationBundle\Publisher\PublisherInterface.