diff options
author | Valentin Popov <info@valentineus.link> | 2017-11-23 18:18:32 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2017-11-23 18:29:36 +0300 |
commit | 05512c5440ff6d2bbb31e6e5d886c83e8510f15d (patch) | |
tree | 510d8502d39efb0f6aa1891ec8b5a238a41f3dea | |
parent | 91754489b0471e5c101e73cd4c239329752d5248 (diff) | |
download | local_webhooks-05512c5440ff6d2bbb31e6e5d886c83e8510f15d.tar.xz local_webhooks-05512c5440ff6d2bbb31e6e5d886c83e8510f15d.zip |
Repeated refactoring of the event handler
-rw-r--r-- | classes/handler.php | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/classes/handler.php b/classes/handler.php index 4e102af..cb32112 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -26,6 +26,8 @@ namespace local_webhooks; defined("MOODLE_INTERNAL") || die(); +require_once(__DIR__ . "/../lib.php"); + require_once($CFG->libdir . "/filelib.php"); /** @@ -42,16 +44,6 @@ class handler { */ public static function events($event) { $data = $event->get_data(); - self::transmitter($data); - } - - /** - * Transmitter, processing event and services. - * - * @param array $data - */ - private static function transmitter($data) { - global $DB; if ($callbacks = local_webhooks_get_list_records()) { foreach ($callbacks as $callback) { @@ -70,17 +62,12 @@ class handler { global $CFG; if (boolval($callback->enable)) { - if (!empty($events[$data["eventname"]])) { - $urlparse = parse_url($CFG->wwwroot); - $data["host"] = $urlparse['host']; - - if (!empty($callback->token)) { - $data["token"] = $callback->token; - } + if (!empty($data["eventname"])) { + $urlparse = parse_url($CFG->wwwroot); - if (!empty($callback->other)) { - $data["extra"] = $callback->other; - } + $data["host"] = $urlparse['host']; + $data["token"] = $callback->token; + $data["extra"] = $callback->other; self::send($data, $callback); } @@ -95,7 +82,7 @@ class handler { */ private static function send($data, $callback) { $curl = new \curl(); - $curl->setHeader(array("Content-Type: application/$callback->type")); + $curl->setHeader(array("Content-Type: application/" . $callback->type)); $curl->post($callback->url, json_encode($data)); $response = $curl->getResponse(); |