wooshell/store-notifier

基于 Symfony EventDispatcher 的 PHP 通知器。在事件触发时发送通知。提供文件存储以跟踪通知。

dev-master 2013-08-03 08:39 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:52:32 UTC


README

基于 Symfony EventDispatcher 的 PHP 通知器。

  • 在事件触发时发送通知。
  • 提供文件存储以跟踪通知。

安装

$ composer install --dev

商店使用

商店注册

use wooshell\storeNotifier\StoreNotifier;

$myStoreDir = '/tmp/myStoreDir';
$myStore = 'cars';
$myStoreEntry = 'Smart Hayabusa';

$storeNotifier = new StoreNotifier($myStoreDir);

$storeNotifier->store($myStore);
$storeNotifier->store(...);

$store->log($myStoreEntry);

商店通知

if (false === $store->exists($myStore, $myStoreEntry)) {
    $summary = '...';
    $body = '...';
    $store->send($summary, $body);
}

商店锁定

$lockFilepath = '/tmp/storeNotifier.lock';
$store->lock($lockFilepath );
...
$store->unlock($lockFilepath );

自定义通知

创建监听器

use Symfony\Component\EventDispatcher\Event;
use wooshell\storeNotifier\EventDispatcher\Events\SendEvent;
use wooshell\storeNotifier\EventDispatcher\Listeners\ListenerInterface;

class EchoListener implements ListenerInterface
{
    /**
     * @param Event $event
     */
    public function send(Event $event)
    {
        /** @var SendEvent $event */
        echo($event->getSummary(), $event->getBody()));
    }
}

将监听器添加到商店通知器

$store->getDispatcher()->addListener(SendEvent::EVENT_SEND, array(new EchoListener() , 'send'));