From 2e1a89faf392ebc635d427668cb7072f8f51243b Mon Sep 17 00:00:00 2001 From: Pavel Zotikov Date: Mon, 16 Sep 2024 18:50:15 +0300 Subject: [PATCH] Fix: Use json_encode for event serialization in POST fields --- src/Event.php | 4 ++-- src/Transport/CurlTransport.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Event.php b/src/Event.php index c8f9cc1..1862ab7 100644 --- a/src/Event.php +++ b/src/Event.php @@ -9,7 +9,7 @@ * * @package Hawk */ -final class Event +final class Event implements \JsonSerializable { /** * @var string @@ -53,7 +53,7 @@ public function getEventPayload(): EventPayload /** * @return array */ - public function jsonSerialize() + public function jsonSerialize(): array { return [ 'token' => $this->integrationToken, diff --git a/src/Transport/CurlTransport.php b/src/Transport/CurlTransport.php index 07d63cc..797a6e4 100644 --- a/src/Transport/CurlTransport.php +++ b/src/Transport/CurlTransport.php @@ -53,7 +53,7 @@ public function send(Event $event) $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $this->url); curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $event->jsonSerialize()); + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($event, JSON_UNESCAPED_UNICODE)); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 10);