gigafoxweb/notifier 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gigafoxweb/notifier

Composer 安装命令:

composer require gigafoxweb/notifier

包简介

Simple notifier manager

README 文档

README

Thank you for your interest in this product. I hope you will enjoy it. gigafoxweb.com.

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

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);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!-- notifications output start -->
    <?= Notifier::instance()->getHandler('output')->processStorage(Notifier::instance()->getStorage('memory')); ?>
    <?= Notifier::instance()->getHandler('output')->processStorage(Notifier::instance()->getStorage('session')); ?>
    <!-- notifications output end -->
    <form action="" method="post">
        <label for="some-input">Some input</label>
        <input type="text" id="some-input" name="some-input">
        <input type="submit">
    </form>
</body>
</html>

统计信息

  • 总下载量: 99
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固