PHPackages                             snebes/notifications - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. snebes/notifications

ActiveLibrary[Database &amp; ORM](/categories/database)

snebes/notifications
====================

Notifications component

v1.0.1(6y ago)02581MITPHPPHP ^7.1.3

Since Sep 11Pushed 6y ago1 watchersCompare

[ Source](https://github.com/snebes/notifications)[ Packagist](https://packagist.org/packages/snebes/notifications)[ Docs](https://github.com/snebes/notifications)[ RSS](/packages/snebes-notifications/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (1)

Notifications
=============

[](#notifications)

[![GitHub release](https://camo.githubusercontent.com/be437273eb939a7b51b1b6cd637797d726e7a931c05b3910dafc928fc2dca18b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736e656265732f6e6f74696669636174696f6e73)](https://camo.githubusercontent.com/be437273eb939a7b51b1b6cd637797d726e7a931c05b3910dafc928fc2dca18b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f736e656265732f6e6f74696669636174696f6e73)[![GitHub license](https://camo.githubusercontent.com/f350a45edd1313a40930a122f31a5fb7925c06ce74822fe22aac1edd927caae1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736e656265732f6e6f74696669636174696f6e73)](https://github.com/snebes/notifications/blob/master/LICENSE)[![Scrutinizer build](https://camo.githubusercontent.com/cab5ed2394010848e6cb1006ac35c0f6f051422ca0dc6120652849b54a04d5b5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f736e656265732f6e6f74696669636174696f6e73)](https://camo.githubusercontent.com/cab5ed2394010848e6cb1006ac35c0f6f051422ca0dc6120652849b54a04d5b5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f736e656265732f6e6f74696669636174696f6e73)[![Scrutinizer coverage](https://camo.githubusercontent.com/4f273b368f7d03fa34a48754c3d996d7bd23b56adbc539fbf86e7ba366277980/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f736e656265732f6e6f74696669636174696f6e73)](https://camo.githubusercontent.com/4f273b368f7d03fa34a48754c3d996d7bd23b56adbc539fbf86e7ba366277980/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f736e656265732f6e6f74696669636174696f6e73)[![Scrutinizer code quality](https://camo.githubusercontent.com/315fad609867fe854574a3d7745822c1a7f25ca09b268787c31b70f9bfc33a6c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f736e656265732f6e6f74696669636174696f6e733f6c6f676f3d7363727574696e697a6572)](https://camo.githubusercontent.com/315fad609867fe854574a3d7745822c1a7f25ca09b268787c31b70f9bfc33a6c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f736e656265732f6e6f74696669636174696f6e733f6c6f676f3d7363727574696e697a6572)[![PHP](https://camo.githubusercontent.com/d9eb52076c33d85552008d09f54a025bb9bfdd4e0cd838a8e678cc184f622696/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f736e656265732f6e6f74696669636174696f6e73)](https://camo.githubusercontent.com/d9eb52076c33d85552008d09f54a025bb9bfdd4e0cd838a8e678cc184f622696/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f736e656265732f6e6f74696669636174696f6e73)

`snebes/notifications` is an abstraction layer, inspired by [Laravel](https://laravel.com), which allows you to easily add support for email and web-interface messaging.

Prerequisites
-------------

[](#prerequisites)

This bundle utilizes Symfony 3.4+ components as well as `SwiftMailer` to provide notifications.

Installation
------------

[](#installation)

Add `snebes/notifications` to your `composer.json` file:

```
composer require snebes/notifications
```

If you are looking for to use this component in a Symfony 3.4+ based application, the `snebes/notifications-bundle` can be installed to simplify this configuration. [Check out the bundle documentation.](https://github.com/snebes/notifications-bundle)

Setup / Bootstrap
-----------------

[](#setup--bootstrap)

The Notifications component is build around Symfony's Event Dispatcher, which is commonly used in the PHP ecosystem.

```
use Symfony\Component\EventDispatcher\EventDispatcher;

$eventDispatcher = new EventDispatcher();
$notificationSender = new NotificationSender($eventDispatcher);
```

#### Notification Channels

[](#notification-channels)

Register the database channel to utilize web-interface notifications. The database channel included in this component depends on Doctrine.

```
$databaseChannel = new DatabaseChannel($doctrineEntityManager);
$eventDispatcher->addListener(NotificationEvents::SEND, [$databaseChannel, 'send']);
```

Register the mail channel to utilize email notifications. The mail channel included in this component depends on SwiftMailer.

```
$transport = new Swift_SmtpTransport('smtp.example.org', 25);
$mailer = new SwiftMailerMailer(new Swift_Mailer($transport));

$mailChannel = new MailChannel($mailer);
$eventDispatcher->addListener(NotificationEvents::SEND, [$mailChannel, 'send']);
```

Sending Notifications
---------------------

[](#sending-notifications)

Notifications may be sent by the `NotificationSender` service.

```
