承接 codekanzlei/cake-notifications 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

codekanzlei/cake-notifications

Composer 安装命令:

composer require codekanzlei/cake-notifications

包简介

CakePHP3 Notifications Plugin

README 文档

README

CakePHP 3 Notifications Plugin

Build Status Code Coverage v2-dev License

A CakePHP 3.8 notification plugin which can send out emails asynchronously through to the cakephp-queuesadilla job queue.

Requirements

Installation

1. Install the plugin via composer

composer require codekanzlei/cake-notifications

2. Load the plugin in your src/Application.php

$this->addPlugin('Notifications');

3. Configure config/app.php

Set your default locale in a config file, for example in app.php. This config is mandatory and will cause an exception if not set.

'Notifications' => [
    'defaultLocale' => 'en_US'
]

You can also override the queue options like attempts, attempts_delay, delay, expires_in and queue.

'Notifications' => [
    'queueOptions' => [
        'queue' => 'notification'
    ]
]

This doesn't affect the use of queueOptions() later. You can still override the options there.

Also, be sure to set up the the cakephp-queuesadilla plugin config. You can find an example config here: https://cakephp-queuesadilla.readthedocs.io/en/latest/.

Or you can find available config options inside your used Engine file (vendor/josegonzalez/queuesadilla/src/josegonzalez/Queuesadilla/Engine/*Engine.php) inside the $baseConfig property.

IMPORTANT: Set "date.timezone" in your cli/php.ini to an appropriate value, else notifications with a delay_until could be sent out at the wrong time.

Usage

Email

The EmailNotification is completely compatible with the CakePHP Email.

Add the following to your class where you want to send an email:

use Notifications\Notification\EmailNotification;

Then simply create a new EmailNotification object.

$email = new EmailNotification();
$email->to('john.doe@example.com')
    ->setSubject('Send with cake-notifications v2')
    ->send('Hello :)');

You can chain all methods provided by the CakePHP Email Class http://book.cakephp.org/3.0/en/core-libraries/email.html

Additional, following functions are available:

send( array|string|null $content null )

Send out the email immediately. before- and afterSend callbacks are still available

setLocale( string|null $locale null )

Set the locale for the notification. If null, Configure::read('Notifications.defaultLocale') is used.

push()

Push the email into the queue to send it asynchronous

setQueueOptions( array $options null )

You can change some of the default options from the cakephp-queuesadilla plugin.

Supported options:

  • attempts how often the notification will be executed again after a failure
  • attempts_delay how long it takes in seconds until the notification will be executed again
  • delay how long it takes until the notification will be executed for the first time in seconds
  • expires_in how long the notification will stay in the queue in seconds
  • queue name of the queue

setBeforeSendCallback( array|string|null $class null, array $args [] )

Pass a callable as the $class parameter. Static and none-static functions are supported.

$email->beforeSendCallback(['Foo', 'bar'], ['first_param', 'second_param'])

This will call the bar method inside the Foo class with two parameters before the email is send.

To manipulate the EmailNotification instance before sending, the beforeSendCallback may return a function taking the notification instance reference and for example changing the profile. The bar method may then look something like this:

public function bar($first_param, $second_param)
{
    // do something
    return function (&$instance) {
        $instance->profile([
            'from' => 'email@example.com'
        ]);
    };
}

setAfterSendCallback( array|string|null $class null, array $args [] )

Pass a callable as the $class parameter. Static and none-static functions are supported.

$email-> afterSendCallback(['Foo::bar'], ['first_param', 'second_param'])

This will call the static bar method inside the Foo class with two parameters after the email was send.

addBeforeSendCallback( array|string|null $class null, array $args [] )

Add an additional callback to beforeSend.

addAfterSendCallback( array|string|null $class null, array $args [] )

Add an additional callback to afterSend.

codekanzlei/cake-notifications 适用场景与选型建议

codekanzlei/cake-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44.43k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 codekanzlei/cake-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codekanzlei/cake-notifications 我们能提供哪些服务?
定制开发 / 二次开发

基于 codekanzlei/cake-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 4
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-28