定制 cvo-technologies/cakephp-notifier 二次开发

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

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

cvo-technologies/cakephp-notifier

Composer 安装命令:

composer require cvo-technologies/cakephp-notifier

包简介

CvoTechnologies/Notifier plugin for CakePHP

README 文档

README

Software License Build Status Coverage Status Total Downloads Latest Stable Version

Usage

Configuring notifications transports

Add the following section to your application config in app.php.

    'NotificationTransport' => [
        'email' => [
            'className' => 'CvoTechnologies/Notifier.Email',
            'profile' => 'default',
        ],
        'irc' => [
            'className' => 'Irc',
            'channel' => '#cvo-technlogies'
        ],
        'twitter' => [
            'className' => 'CvoTechnologies/Twitter.Twitter',
        ],
        'example' => [
            'className' => 'Example',
            'someOption' => true
        ]
    ],

Creating a notifier

namespace App\Notifier;

use CvoTechnologies\Notifier\Notifier;

class UserNotifier extends Notifier
{
    public function welcome($user)
    {
        $this
            ->to([
                'irc' => $user->irc_nickname,
                'twitter' => $user->twitter_nickname
            ])
            ->subject(sprintf('Welcome %s', $user->name))
            ->template('welcome_message') // By default template with same name as method name is used.
            ->viewVars([
                'user' => $user
            ])
            ->transports([
                'irc',
                'twitter'
            ]);
    }
}

Creating notification template

Create a template file in Template/Notification/transport-type. This will be used as template for the notification.

For example: Template/Notification/irc/welcome.ctp

Welcome <?= $user->name; ?> to our website!

Using it

Using the notifier is very easy. Here's an example on how to use it in a controller:

namespace App\Controller;

use CvoTechnologies\Notifier\NotifierAwareTrait;

class UsersController extends AppController
{
    use NotifierAwareTrait;

    public function register()
    {
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->data())
            if ($this->Users->save($user)) {
                $this->getNotifier('User')->send('welcome', [$user]);
            }
        }
        $this->set('user', $user);
    }
}

Creating a transport

A transport is used to talk to a particular service.

It can accept configuration options that are passed from the NotificationTransport section in your application config.

<?php

namespace App\Notifier\Transport;

use CvoTechnologies\Notifier\AbstractTransport;

class ExampleTransport extends AbstractTransport
{
    const TYPE = 'example';

    /**
     * Send notification.
     *
     * @param \CvoTechnologies\Notifier\Notification $notification Notification instance.
     * @return array
     */
    public function send(Notification $notification)
    {
        // Send notificaiton
        $result = NotificationSendingService::send($notification->message(static::TYPE));

        return (array)$result;
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固