Skip to content

Commit 6ed6259

Browse files
committed
add webhook helper
1 parent efbf616 commit 6ed6259

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/Facade/Webhook.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* Webhook Helper
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
namespace OpenTHC\SSO\Facade;
9+
10+
class Webhook {
11+
12+
/**
13+
* Calls the Webhook, Ignores Response
14+
*/
15+
static function emit(string $action, array $ctx) : void {
16+
17+
$url = \OpenTHC\Config::get('webhook/url');
18+
if (empty($url)) {
19+
return;
20+
}
21+
22+
// PreShared Key
23+
$psk = \OpenTHC\Config::get('webhook/psk');
24+
25+
$req = _curl_init($url);
26+
$arg = [];
27+
$arg['action'] = $action;
28+
$arg['context'] = $ctx;
29+
$arg = json_encode($arg);
30+
31+
// From Common
32+
_curl_post_json($url, $arg, [
33+
'authorization' => sprintf('openthc-psk %s', $psk)
34+
]);
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)