faeland/notifire-bundle

1.0.0 2019-09-27 14:55 UTC

This package is auto-updated.

Last update: 2024-08-28 01:53:18 UTC


README

Build Status

Notifire Bundle 提供将 Notifire 库集成到 Symfony 框架中的功能。

Notifire 是一个PHP库,它集中管理通知(电子邮件、短信、推送通知等),查看其 GitHub 页面 了解更多信息。

需求

  • php >= 7.0
  • symfony/symfony >= 2.8
  • fazland/notifire

安装

建议的安装方法是使用 composer

$ composer require fazland/notifire-bundle

使用 Notifire Bundle

首先,在您的 AppKernel.php 中注册 NotifireBundle

public function registerBundles()
{
    return [
        // ...
        new NotifireBundle(),
        // ...
    ];
}

Notifire Bundle 的配置很简单,只需在您的 app/config/config.xml(或等效)中包含以下内容:

<notifire:config>
    <notifire:email auto_configure_swiftmailer="true">
        <notifire:mailer name="mailgun_example"
            provider="mailgun" api_key="api_key" domain="example.org" />
    </notifire:email>
    <notifire:sms>
        <notifire:service name="default_sms" provider="twilio"
                          username="%twilio_account_sid%"
                          password="%twilio_auth_token%"
                          sender="%twilio_from_phone%" />
    </notifire:sms>
</notifire:config>

YAML 版本

notifire:
    email:
        auto_configure_swiftmailer: true
        mailers:
            mailgun_example:
                provider: mailgun
                api_key: api_key
                domain: example.org
    sms:
        services:
            default_sms:
                provider: twilio
                account_sid: '%twilio_account_sid%'
                auth_token: '%twilio_auth_token%'
                from_phone: '%twilio_from_phone%'
                

此配置片段将所有现有的 SwiftMailer 邮件程序、指定的 Twilio 服务和 Mailgun 邮件程序注册到 Notifire

如果您只想注册一组 SwiftMailer 邮件程序实例,请使用

<!-- ... -->
    <notifire:email auto_configure_swiftmailer="false">
        <notifire:mailer name="y_mail" 
            provider="swiftmailer" mailer_name="%your_mailer%" />
    </notifire:email>
<!-- ... -->

或 YAML 格式

# ...
    email:
        auto_configure_swiftmailer: false
        mailers:
            y_mail:
                provider: swiftmailer
                mailer_name: '%your_mailer%'
# ... 

此配置将为您的容器中的 Notifire 提供配置和设置,并准备就绪以发送通知的 handlers

像往常一样,只需创建一个通过 Notifire::email() 创建的电子邮件并发送即可。

// Use 'default' mailer
$email = Notifire::email('default');

$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 Bundle 在 MIT 许可下授权 - 详细信息请参阅 LICENSE 文件。