fazland / notifire
1.0.0
2019-04-16 09:40 UTC
Requires
- php: >=7.0
- psr/log: ^1.0
- symfony/event-dispatcher: ^2.7|^3.0|^4.0
- symfony/options-resolver: ^2.7|^3.0|^4.0
Requires (Dev)
- fazland/skebby-rest-client: ^0.2@dev
- mailgun/mailgun-php: ^2.0
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^6.0
- sendgrid/sendgrid: ^5.1
- swiftmailer/swiftmailer: ^5.4
- twig/twig: ^1.24
- twilio/sdk: ^4.10|^5.0
Suggests
- fazland/skebby-rest-client: Send SMS via Skebby
- mailgun/mailgun-php: Send emails via Mailgun
- sendgrid/sendgrid: Send email via Sendgrid
- twilio/sdk: Send SMS via Twilio
Conflicts
This package is auto-updated.
Last update: 2024-09-14 21:38:01 UTC
README
Notifire 是一个 PHP 库,用于集中管理通知(电子邮件、短信、推送通知等)。
要求
php
>= 7.2symfony/event-dispatcher
>= 4.3symfony/options-resolver
>= 4.3
安装
建议的安装方法是使用 composer
$ composer require fazland/notifire
使用 Notifire
Notifire 中的每个通知都会触发一个事件(NotifyEvent
),该事件将由 NotifyEventSubscriber
的实例(后来命名为 handlers
)处理。这些通知必须实现 NotificationInterface
并通过 Notifire::addNotification()
注册,以便 Notifire 可以读取。
Notifire 提供了 2 个标准实现(Email
和 Sms
)及其 handlers
(默认为 SwiftMailerHandler
和 TwilioHandler
)。
Notifire 非常易于使用
初始化
首先,Notifire 必须被初始化。有两种方式
- 运行以自动配置电子邮件使用 SwiftMailer 作为其
Handler
Notifire::create();
- 使用
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()
,填写如 from
、to
、parts
等字段,然后使用 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 文件