fazland/notifire

1.0.0 2019-04-16 09:40 UTC

This package is auto-updated.

Last update: 2024-09-14 21:38:01 UTC


README

Build Status

Notifire 是一个 PHP 库,用于集中管理通知(电子邮件、短信、推送通知等)。

要求

  • php >= 7.2
  • symfony/event-dispatcher >= 4.3
  • symfony/options-resolver >= 4.3

安装

建议的安装方法是使用 composer

$ composer require fazland/notifire

使用 Notifire

Notifire 中的每个通知都会触发一个事件(NotifyEvent),该事件将由 NotifyEventSubscriber 的实例(后来命名为 handlers)处理。这些通知必须实现 NotificationInterface 并通过 Notifire::addNotification() 注册,以便 Notifire 可以读取。

Notifire 提供了 2 个标准实现(EmailSms)及其 handlers(默认为 SwiftMailerHandlerTwilioHandler)。

Notifire 非常易于使用

初始化

首先,Notifire 必须被初始化。有两种方式

  1. 运行以自动配置电子邮件使用 SwiftMailer 作为其 Handler
Notifire::create();
  1. 使用 NotifireBuilder 进行自定义配置,通过注册通知和所需的 EventDispatcherInterface 实例
require_once('vendor/autoload.php');

$dispatcher = new EventDispatcher();

$builder = NotifireBuilder::create()
    ->setDispatcher($dispatcher)
;

$builder->addHandler(new SwiftMailerHandler($mailer, 'mailer_one'));
$builder->addNotification('email', Email::class);

$builder->initialize();

现在你已经准备好了!要创建一个 Email,只需使用 Notifire::email(),填写如 fromtoparts 等字段,然后使用 Email::send()

// Use 'mailer_one' handler to send this message
$email = Notifire::email('mailer_one');

$email
    ->addFrom('test@fazland.com')
    ->addTo('info@example.org')
    ->setSubject('Only wonderful E-mails with Notifire!')
    ->addPart(Part::create($body, 'text/html'))
    ->send()
;

贡献

欢迎贡献。请随意在此 GitHub 上提交 PR 或提交问题!

许可证

Notifire 在 MIT 许可证下发布 - 有关详细信息,请参阅 LICENSE 文件