From eb4b9b69f862df8ba23cafc8cd5e4a887baa02f0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 6 May 2019 05:45:35 +0400 Subject: Added worked a class observer Signed-off-by: Valentin Popov --- classes/event/observer.php | 44 ++++++++++++++++++++++++++++++++++++++++++ classes/event_observer.php | 48 ---------------------------------------------- classes/task/notify.php | 2 +- 3 files changed, 45 insertions(+), 49 deletions(-) create mode 100644 classes/event/observer.php delete mode 100644 classes/event_observer.php (limited to 'classes') diff --git a/classes/event/observer.php b/classes/event/observer.php new file mode 100644 index 0000000..ff6a89e --- /dev/null +++ b/classes/event/observer.php @@ -0,0 +1,44 @@ +. + +namespace local_webhooks\event; + +defined('MOODLE_INTERNAL') || die(); + +use core\event\base as event; +use core\task\manager; +use local_webhooks\task\notify; +use function defined; + +/** + * Class observer. + * + * @copyright 2019 'Valentin Popov' + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package local_webhooks\event + */ +final class observer { + /** + * Main handler for events. + * + * @param \core\event\base $event + */ + public static function handler(event $event) { + $task = new notify(); + $task->set_custom_data($event->get_data()); + manager::queue_adhoc_task($task); + } +} \ No newline at end of file diff --git a/classes/event_observer.php b/classes/event_observer.php deleted file mode 100644 index 983552a..0000000 --- a/classes/event_observer.php +++ /dev/null @@ -1,48 +0,0 @@ -. - -/** - * Handlers of observers for events. - * - * @copyright 2018 'Valentin Popov' - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @package local_webhooks - */ - -namespace local_webhooks; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Defines event handlers. - * - * @copyright 2018 'Valentin Popov' - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @package local_webhooks - */ -class event_observer { - /** - * Handler of all the events. - * Each event is put into the job queue. - * - * @param object $event - */ - public static function observe_all($event) { - $task = new \local_webhooks\task\process_events_task(); - $task->set_custom_data($event->get_data()); - \core\task\manager::queue_adhoc_task($task); - } -} \ No newline at end of file diff --git a/classes/task/notify.php b/classes/task/notify.php index faa68a9..bd11f24 100644 --- a/classes/task/notify.php +++ b/classes/task/notify.php @@ -79,7 +79,7 @@ final class notify extends adhoc_task { public function post(record $service, array $data) { $curl = new curl(); $curl->setHeader(['Content-Type: ' . $service->header]); - $curl->post($service->point, $data); + $curl->post($service->point, json_encode($data)); if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) { $this->debug = array_merge($this->debug ?? [], [ -- cgit v1.2.3