affittocertificato/pushnotificationhandler

Affitto Certificato 的轻量级推送通知实现

1.0.6 2019-11-29 16:07 UTC

This package is auto-updated.

Last update: 2024-09-16 02:56:02 UTC


README

来自 Affitto Certificato 的简单快速推送通知处理实现

Latest Stable Version License

基本示例

require_once __DIR__.'/../src/NotificationHandler.php';

$handler = new AffittoCertificato\NotificationHandler();

// this call register to a basic event named 'sharingCurriculum'. 
// In other words the method ->onCurriculum(...) is an alias to ->on('sharingCurriculum', ...)
$handler->onCurriculum(function($data){

  // do your logic with $data 
  // code ...
  // code ...
  // code ...
  // code ...
});


// this call register to an event named 'eventname_not_yet_implemented'
$handler->on('eventname_not_yet_implemented', function($data){
  return "You should implement this awesome event... really";
});

// run the push notification handler logic and return results to the AffittoCertificato caller
$handler->run();

// that's it!

回调函数应该做什么?

如果回调函数想要通知调用者出了问题,它 必须 抛出一个包含描述性注释的异常

以下是在 onCurriculum 事件中实现简单逻辑的示例

$handler->onCurriculum(function($data){

  if (!isset ($data->curriculumLink))
    throw new Exception("Hey! You don't have passed me the link");


  // do some logics with curriculumLink
  // code ...
  // code ...
  // code ...
  // code ...
});

回调函数可以返回一个值(非强制,可以是任何期望的格式 [字符串,对象,数字,...]) 作为对操作结果的进一步描述,如果有的话,它将被添加到 json 响应中,并传递给 AffittoCertificato 调用者。

$handler->onCurriculum(function($data){

    // do your logics
  // code ...
  // code ...
  // code ...
  // code ...

  return "Have a nice day!";


});

在这种情况下,调用者(Affitto Certificato)将从处理者(你)那里收到字符串 "祝您愉快!" 作为有效负载。这些信息将被用作日志信息和进一步调试活动。

onCurriculum $data 格式

onCurriculum 回调在 $data 参数中接收一个对象,结构如下

$data->code; // is the code of rental listing you chose during button creation
$data->curriculumLink; // is the address that link to the tenant's curriculum
$data->userName; // Tenant's full name, such as "John Smith"

要求

  • PHP >= 5.6

安装

推荐的方式是通过 Composer 安装库。

只需运行 composer require affittocertificato/pushnotificationhandler,它将自动安装并包含在您的 composer.json 中。

现在您可以使用自动加载器,您将有权访问库

require 'vendor/autoload.php';

许可证

此库根据 GPL-3.0 许可证发布