fazland/notifire-bundle

1.0.0 2019-09-27 14:55 UTC

This package is auto-updated.

Last update: 2022-04-27 21:05:10 UTC


README

Build Status

Notifire Bundle provides integration of Notifire library into the Symfony Framework.

Notifire is a PHP library that centralizes the management of notifications (e-mails, sms, push notifications, etc.), check its GitHub page to learn more.

Requirements

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

Installation

The suggested installation method is via composer:

$ composer require fazland/notifire-bundle

Using Notifire Bundle

First of all, register NotifireBundle in your AppKernel.php:

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

The configuration of Notifire Bundle is simple, just include in your app/config/config.xml (or equivalent) something like the following:

<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 version:

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%'
                

This configuration snippet registers in Notifire all your existing SwiftMailer's mailers, the specified Twilio's services and Mailgun's mailers.

If you want to register by instance only a set of SwiftMailer` mailers just use:

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

or in YAML:

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

This configuration will provide Notifire configured and set in your container and its handlers ready to send your notifications!

As usual, just create an e-mail with Notifire::email() and send it:

// 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()
;

Contributing

Contributions are welcome. Feel free to open a PR or file an issue here on GitHub!

License

Notifire Bundle is licensed under the MIT License - see the LICENSE file for details