Skip to content

Commit 19c76cc

Browse files
authored
add response logger (useful when debugging)
1 parent 886af90 commit 19c76cc

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Fcm.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Fcm
2020

2121
protected $serverKey;
2222

23+
protected $responseLogEnabled = false;
24+
2325
public function __construct($serverKey)
2426
{
2527
$this->serverKey = $serverKey;
@@ -73,11 +75,18 @@ public function timeToLive($timeToLive)
7375

7476
return $this;
7577
}
76-
78+
7779
public function setPackage($package)
7880
{
7981
$this->package = $package;
80-
82+
83+
return $this;
84+
}
85+
86+
public function enableResponseLog($enable = true)
87+
{
88+
$this->responseLogEnabled = $enable;
89+
8190
return $this;
8291
}
8392

@@ -117,7 +126,13 @@ public function send()
117126
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
118127
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, CURL_IPRESOLVE_V4);
119128
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payloads));
120-
$result = json_decode(curl_exec($ch), true);
129+
$response = curl_exec($ch);
130+
131+
if ($this->responseLogEnabled) {
132+
logger('laravel-fcm', ['response' => $response]);
133+
}
134+
135+
$result = json_decode($response, true);
121136
curl_close($ch);
122137

123138
return $result;

0 commit comments

Comments
 (0)