noveth/notify 问题修复 & 功能扩展

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

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

noveth/notify

最新稳定版本:0.2.5

Composer 安装命令:

composer require noveth/notify

包简介

A PHP notification library for sending messages to various platforms

README 文档

README

Notification library

Description

A PHP Library that will be used for sending notifications to multiple providers.

##Implementations

Current

  • Email
  • Slack

Planned

  • HipChat

Requirements

  • PHP 5.4+
  • CURL

Installation

Using Composer

To install Notify with Composer, just add the following to your composer.json file:

{
    "require": {
        "noveth/notify": "0.*"
    }
}

or by running the following command:

composer require noveth/notify

Usage

Configuration

There is a default configuration included and falls back to if no user configuration is found. To start using a custom configuration rename Config.php.example to Config.php.

Email

Sending an email with Notify is incredibly simple, you pass 3 parameters and it will return true or false.

bool Notify\Email::send(string $to, string $subject, string $template [, array $replace ] );

There are 3 required parameters used in the send method with an optional 4th parameter if you use string replacement in your templates.

Here is an example of the parameters:

// Target email address
$to = 'example@example.com';

// Subject line
$subject = 'An example email';

// Template file name
// You can tell Notify if its a html email or not depending on the file extension
// .html files will automatically be sent as a html email
$template = 'user/registration.html';

// If you use tags in your template this is where you pass what to replace them with
$replace = [
  'test tag' => 'test content'
];

Slack

Notifications can also be sent to slack but requires a bit more setup than using email (dont worry its not too difficult). To use Slack notifications you need to setup a webhook on your slack team settings first.

Follow the Configuration step above to start using a custom configuration and then add the following lines to your Config.php file.

// Replace {YOUR_ENDPOINT} with the webhook URL provided by slack.
Config::$SLACKWEBHOOK = '{YOUR_ENDPOINT}';
// Replace {NAME_OF_USER} with the user you want the message to be sent as (this can be anything).
Config::$SLACKUSERNAME = '{NAME_OF_USER}';

Slack notifications are sent in a similar fashion to Emails but only has 1 required parameter and 1 optional.

bool Notify\Slack::send(string $message [, string $target]);

The second parameter can either be a room or a user, this is done by following the syntax below. If its not sent it will use the default room set in your webhook settings on slack.

$target = '#channel';
$target = '@user';

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-07