定制 manthan/nuncio 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

manthan/nuncio

最新稳定版本:1.1.1

Composer 安装命令:

composer require manthan/nuncio

包简介

Turn your customer messages/emails into mustache-style templates. Just create one template for your message and nuncio will replace tags with customer details.

README 文档

README

Nuncio is a flexible and customizable messenger that helps you turn your SMS/Email into mustache-style templates.

Installing

You can install Nuncio using Composer.

{
   "require": {
      "manthan/nuncio": "1.1.*"
   }
}

Basic Usage

Using Nuncio is as simple as extending Manthan\Nuncio\Nuncio and specifying Keywords that you'd want in your message templates to be replaced.

For example, you'd like to notify your users via SMS using following template in your dashboard:

Hello {{name}}, Your fees ${{fees}} are pending.

To process this message this is what you'd do:

    use Manthan\Nuncio\Nuncio

    class SMSNotifier extends Nuncio
    {
      protected $keywords = array('name', 'fees');
    }

Looks very simple, right?

Now to use this newly created notifier do the following:

    $SMS_Service = new TwilioService() // This must implement Manthan\Nuncio\MessengerInterface

    $processor = new Manthan\Nuncio\MessageProcessor();
    $notifier = new SMSNotifier($SMS_Service, $processor);

    $user = new stdClass();
    $user->name   = "Manthan";
    $user->fees   = "1500";
    $user->number = "78787878";

    $recepients = [$user];
    $notifier->from('YOUR-NUMBER')->to($recepients)->send($subject, $message);

The code above, sends following message to the number 78787878:

Hello Manthan, your fees $1500 are pending.

Nuncio is super flexible. As shown above, you can use any of your Message Service Implementations (may it be Twilio, Plivo or Email Notifiers) to send your processed messages.

Changing the number field

As you can see in the above example, Nuncio by default looks for the property 'number' on each of the recepients and sends message to that number.

But it is highly probable that you're not using number property in your User objects. In which case, you can change the default number field like so:

    use Manthan\Nuncio\Nuncio

    class SMSNotifier extends Nuncio
    {

      protected $keywords = array('name', 'fees');

      // Suppose your user's phone number is denoted by its phone_number property
      protected $number_field = 'phone_number';
    }

Running Tests

You can run the tests using :

./vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-23