korditpteltd / kd-cakephp-webhooks
KORDIT CakePHP Webhook 插件
dev-master
2020-03-31 08:32 UTC
Requires
- cakephp/cakephp: >3.1.0
This package is auto-updated.
Last update: 2024-09-29 05:36:07 UTC
README
插件包含触发应用程序级别 webhook 事件的纯 JavaScript 文件。插件还包括表文件、SQL 结构以及用于检索 webhook 表信息的默认控制器,以便执行。
要求
- CakePHP 3.1+
安装
- 编辑
composer.json
文件,添加以下行
"repositories":[ { "type": "git", "url": "git@github.com:mohamednizar/kd-cakephp-webhooks.git" } ]
- 添加所需行后的示例
composer.json
{ "name": "korditpteltd/openemis-phpoe", "description": "KORDIT OpenEMIS CORE", "homepage": "https://demo.openemis.org/core", "type": "project", "license": "GPL-2.0", "require": { "php": ">=5.4.16", "cakephp/cakephp": "3.2.6" }, "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump" }, "minimum-stability": "dev", "prefer-stable": true, "repositories":[ { "type": "git", "url": "git@github.com:mohamednizar/kd-cakephp-webhooks.git" } ] }
composer require korditpteltd/kd-cakephp-webhooks "*"
用法
在您的应用程序的 config/bootstrap.php
中添加
// In config/bootstrap.php Plugin::load('Webhook', ['autoload' => true, 'route' => true]);
或者使用 cake 的控制台
bin/cake plugin load -r --autoload Webhook
配置
您需要将事件条目插入到 webhooks 和 webhook_events 表中
webhooks 表
webhook_events 表
使用 JavaScript Webhook
在 ctp 文件中,您可以实现以下事件
// load the javascript file from the plugin $this->Html->script('Webhook.webhook'); // Webhook url link to the webhook controller $webhookListUrl = [ 'plugin' => 'Webhook', 'controller' => 'Webhooks', 'action' => 'listWebhooks' ]; // You may replace \'logout\', with your event name for example \'login\' echo $this->Html->link('Logout Link', 'http://someurl.com/logout', ['onclick' => 'Webhook.triggerEvent(\''.Router::url($webhookListUrl).'\', [\'logout\']);']);
使用后端 CakePHP 客户端服务与 Shell
$Webhooks = TableRegistry::get('Webhook.Webhooks'); // Setting the 'username' parameter will replace the url with the username that you have specified $Webhooks->triggerShell('logout', ['username' => $username]);