PHPackages                             gigafoxweb/notifier - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. gigafoxweb/notifier

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

gigafoxweb/notifier
===================

Simple notifier manager

3.0.2(9y ago)199MITPHPPHP &gt;=5.4.0

Since Feb 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gigafoxweb/Notifier)[ Packagist](https://packagist.org/packages/gigafoxweb/notifier)[ RSS](/packages/gigafoxweb-notifier/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)DependenciesVersions (10)Used By (0)

GigaFoxWeb Notifier
===================

[](#gigafoxweb-notifier)

Thank you for your interest in this product. I hope you will enjoy it. [gigafoxweb.com](http://gigafoxweb.com).

The main task of Notifier is to register system notifications in one place and show them when and where they need.

Installation
============

[](#installation)

```
composer require gigafoxweb/notifier

```

\#Notification Notifications are GigaFoxWeb\\Notifier\\Notification class objects or extending it.

```
$notification = new Notification('message', ['status' => 1]);
```

\#Storage Storage is any extending GigaFoxWeb\\Notifier\\notification\\Storage object. By default gigafoxweb/notifier have two storages: Memory and Session.

```
$memoryStorage = new Memory();
$memoryStorage->setNotification($notification);
```

\#Handler Handler is the object what know what to do with filtrated notifications.

```
$outputHandler = new OutputHandler();
```

\#Notifier Notifier is just the container for GigaFoxWeb\\Notifier\\notification\\Storage and GigaFoxWeb\\Notifier\\notification\\Handler. It is singleton pool what can be called everywhere.

```
Notifier::instance()->setStorage('memory', $memoryStorage);
Notifier::instance()->setHandler('output', $outputHandler);
```

\#Filter Filter used for removing not needle notifications from handling list.

```
$filter = new RequireParam(['some-required-param', 'another-required-param']);
```

\#Filtrator Filtrator is the pool of Filter objects, used in Handler.

```
$filtrator = new Filtrator();
$filtrator->addFilter($filter);
Notifier::instance()->getHandler('output')->setFiltrator($filtrator);
```

\#Simple application example

```
require_once __DIR__ . '/vendor/autoload.php';

use GigaFoxWeb\Notifier\Notifier;
use GigaFoxWeb\Notifier\notification\storages\Memory;
use GigaFoxWeb\Notifier\notification\storages\Session;
use GigaFoxWeb\Notifier\Notification;
use GigaFoxWeb\Notifier\notification\handlers\OutputHandler;
use GigaFoxWeb\Notifier\notification\Filtrator;
use GigaFoxWeb\Notifier\notification\filters\RequireParam;

session_start();

//setting notification storages
Notifier::instance()->setStorage('memory', new Memory());
Notifier::instance()->setStorage('session', new Session('GFW_notifications'));

//add notification into memory storage
Notifier::instance()->getStorage('memory')->setNotification(
    'hello',
    new Notification('Hello man!', ['required-param' => 'some-required-value',])
);

if (isset($_POST['some-input'])) {
    $message = ($_POST['some-input'] === 'valid') ? 'Value is valid' : 'Value is not valid';
    //add notification into session storage
    Notifier::instance()->getStorage('session')->setNotification(
        'some-input-validation',
        new Notification($message, ['required-param' => 'some-required-value'])
    );
}

//create filtrator if we want to use only filtrated notifications
$filtrator = (new Filtrator());
$filtrator->addFilter(new RequireParam(['required-param']));

//create notifications handler
$outputHandler = new OutputHandler(__DIR__ . '/notification-layout.php');

//setting notification filtrator to handler
$outputHandler->setFiltrator($filtrator);

//setting handler
Notifier::instance()->setHandler('output', $outputHandler);
?>

    Document
