轻莓/通知器

用于通过不同传输方式发送用户通知的库

v0.0.3 2016-10-03 10:16 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:20:19 UTC


README

用于通过不同传输方式发送用户通知的库

SensioLabsInsight Build Status codecov

安装

$ composer require mildberry/notifier

用法

<?php

use Mildberry\Notifier\Interfaces\SmsNotifyInterface;
use Mildberry\Notifier\Notifier;
use Mildberry\Notifier\Notify\NotifyCollection;
use Mildberry\Notifier\Notify\SmsNotify;
use Mildberry\Notifier\Transport\VarDumpTransport;

include 'vendor/autoload.php';

$notifier = new Notifier();
$notifier->setNotifyTransport(SmsNotifyInterface::class, (new VarDumpTransport()));

$notifier->send(new SmsNotify('79136703311', 'Hello world'));

$collectionSms = new NotifyCollection();
$collectionSms
    ->push(new SmsNotify('79136703311', 'How a you?'))
    ->push(new SmsNotify('79136703311', 'Where are you?'));

$notifier->sendCollection($collectionSms);

自定义通知

<?php

use Mildberry\Notifier\Interfaces\SmsNotifyInterface;
use Mildberry\Notifier\Notifier;
use Mildberry\Notifier\Notify\Notify;
use Mildberry\Notifier\Transport\VarDumpTransport;

include 'vendor/autoload.php';

class ActivationSms extends Notify implements SmsNotifyInterface
{
    public function __construct($phone, $code)
    {
        $this
            ->setRecipient($phone)
            ->setBody('Your activation code is '.$code)
        ;
    }
}

class RegistrationCompleteSms extends Notify implements SmsNotifyInterface
{
    public function __construct($phone)
    {
        $this
            ->setRecipient($phone)
            ->setBody('Congratulations registration is completed')
        ;
    }
}

$notifier = new Notifier();
$notifier->setNotifyTransport(SmsNotifyInterface::class, (new VarDumpTransport()));

// ... registration process

$notifier->send(new ActivationSms('79136703311', rand(1, 9999)));

// ... registration complete

$notifier->send(new RegistrationCompleteSms('79136703311'));

待办事项

  • 传输文档
  • 存储文档
  • 保存外部ID和从传输保存投递状态
  • 通知查询

许可证

本库采用MIT许可证。完整许可证请见此处