perform / notification-bundle
使用多种发布者发送通知。
Requires (Dev)
- phpunit/phpunit: ^7.5
- symfony/swiftmailer-bundle: ^3.2
Suggests
- symfony/swiftmailer-bundle: To use the email publisher
This package is auto-updated.
Last update: 2024-09-28 01:59:44 UTC
README
这是一个用于在应用程序中使用多种发布者向用户发送通知的Bundle。
使用方法
使用perform_notification.notifier服务发送通知。
创建一个Perform\NotificationBundle\Notification的实例,然后使用Perform\NotificationBundle\Notifier\Notifier来发送它。
通知是一个不可变的值对象,它需要一个实现Perform\NotificationBundle\RecipientInterface的接收者数组、通知类型以及与通知类型相关的任何上下文变量。
您可以指定要使用的发布者,或者留空使用默认发布者。
//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]);
模板
某些发布者使用twig渲染通知,并传入上下文变量。此外,以下变量会自动设置
- currentRecipient - 此消息的接收者标识符(一个通知可以发送给多个接收者)。
- notification - 通知对象。
每个发布者都会在PerformNotificationBundle:<type>:<publisher>.html.twig中查找模板。
例如,使用'local'发布者发送类型为'new_task'的通知,将渲染PerformNotificationBundle:new_task:local.html.twig。
要添加模板而不修改此Bundle,请将它们放置在app/Resources/PerformNotificationBundle/views中。
例如:PerformNotificationBundle:new_task:local.html.twig -> app/Resources/PerformNotificationBundle/views/new_task/local.html.twig。
添加通知发布者
实现Perform\NotificationBundle\Publisher\PublisherInterface。