Notifire is a PHP library that centralizes the management of notifications (e-mails, sms, push notifications, etc.).
php>= 7.2symfony/event-dispatcher>= 4.3symfony/options-resolver>= 4.3
The suggested installation method is via composer:
$ composer require fazland/notifireEvery notification in Notifire triggers an Event (the NotifyEvent) which will be handled by an instance of NotifyEventSubscriber (later named by handlers).
Those notifications must implement NotificationInterface and registered with Notifire::addNotification() in order to be read by Notifire.
Notifire provides 2 standard implementations (Email and Sms) and theirs handlers (the defaults are SwiftMailerHandler and TwilioHandler).
Notifire is really simple to use:
First of all Notifire has to be initialized. Two ways:
- run in order to autoconfigure the e-mail with SwiftMailer as its
Handler
Notifire::create();- custom configuration with
NotifireBuilderby registering the notifications and the desired instance ofEventDispatcherInterface
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();Now you're ready!
To create an Email just use Notifire::email(), fill the fields like from, to, parts etc. and then use Email::send():
// Use 'mailer_one' handler to send this message
$email = Notifire::email('mailer_one');
$email
->addFrom('[email protected]')
->addTo('[email protected]')
->setSubject('Only wonderful E-mails with Notifire!')
->addPart(Part::create($body, 'text/html'))
->send()
;Contributions are welcome. Feel free to open a PR or file an issue here on GitHub!
Notifire is licensed under the MIT License - see the LICENSE file for details