From 7716840ef35af9032b88476df853a4871ab50966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Leidorf?= Date: Thu, 3 Mar 2022 10:28:57 +0100 Subject: [PATCH] fix: type fixes --- src/Pusher.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Pusher.php b/src/Pusher.php index 7e5b6eb..1ef46a2 100755 --- a/src/Pusher.php +++ b/src/Pusher.php @@ -472,6 +472,10 @@ public static function array_implode($glue, $separator, $array) */ public function trigger($channels, $event, $data, $params = array(), $already_encoded = false) { + if (!isset($params)) { + $params = []; + } + if (is_string($channels) === true) { $channels = array($channels); } @@ -512,7 +516,7 @@ public function trigger($channels, $event, $data, $params = array(), $already_en $post_params = array(); $post_params['name'] = $event; - $post_params['data'] = $data_encoded; + $post_params['data'] = json_encode($data_encoded); $post_params['channels'] = array_values($channels); $all_params = array_merge($post_params, $params); @@ -533,9 +537,13 @@ public function trigger($channels, $event, $data, $params = array(), $already_en throw new ApiErrorException($response['body'], $response['status']); } - $result = json_decode($response['body']); + if (!is_array($response)) { + $result = json_decode($response['body'], true); + } else { + $result = $response; + } - if (property_exists($result, 'channels')) { + if (array_key_exists('channels', $result)) { $result->channels = get_object_vars($result->channels); }