Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit b9191b5

Browse files
committed
Support for multiple accounts i.e. combinations of Sender ID and Server Key
1 parent 4caeb22 commit b9191b5

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/Request/Request.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class Request extends BaseRequest
5252
* @param PayloadNotification $notification
5353
* @param PayloadData $data
5454
* @param Topics|null $topic
55+
* @param string $senderId
56+
* @param string $serverKey
5557
*/
56-
public function __construct($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null, Topics $topic = null)
58+
public function __construct($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null, Topics $topic = null, $senderId = null, $serverKey = null)
5759
{
5860
parent::__construct();
5961

@@ -62,6 +64,14 @@ public function __construct($to, Options $options = null, PayloadNotification $n
6264
$this->notification = $notification;
6365
$this->data = $data;
6466
$this->topic = $topic;
67+
68+
if ($senderId !== null) {
69+
$this->config['sender_id'] = $senderId;
70+
}
71+
72+
if ($serverKey !== null) {
73+
$this->config['server_key'] = $serverKey;
74+
}
6575
}
6676

6777
/**

src/Sender/FCMSender.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class FCMSender extends HTTPSender
2323
* @param Options|null $options
2424
* @param PayloadNotification|null $notification
2525
* @param PayloadData|null $data
26+
* @param string $senderId
27+
* @param string $serverKey
2628
*
2729
* @return DownstreamResponse|null
2830
*/
29-
public function sendTo($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
31+
public function sendTo($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null, $senderId = null, $serverKey = null)
3032
{
3133
$response = null;
3234

@@ -45,7 +47,7 @@ public function sendTo($to, Options $options = null, PayloadNotification $notifi
4547
}
4648
}
4749
} else {
48-
$request = new Request($to, $options, $notification, $data);
50+
$request = new Request($to, $options, $notification, $data, null, $senderId, $serverKey);
4951
$responseGuzzle = $this->post($request);
5052

5153
$response = new DownstreamResponse($responseGuzzle, $to, $this->logger);
@@ -61,12 +63,14 @@ public function sendTo($to, Options $options = null, PayloadNotification $notifi
6163
* @param Options|null $options
6264
* @param PayloadNotification|null $notification
6365
* @param PayloadData|null $data
66+
* @param string $senderId
67+
* @param string $serverKey
6468
*
6569
* @return GroupResponse
6670
*/
67-
public function sendToGroup($notificationKey, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
71+
public function sendToGroup($notificationKey, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null, $senderId = null, $serverKey = null)
6872
{
69-
$request = new Request($notificationKey, $options, $notification, $data);
73+
$request = new Request($notificationKey, $options, $notification, $data, null, $senderId, $serverKey);
7074

7175
$responseGuzzle = $this->post($request);
7276

@@ -80,12 +84,14 @@ public function sendToGroup($notificationKey, Options $options = null, PayloadNo
8084
* @param Options|null $options
8185
* @param PayloadNotification|null $notification
8286
* @param PayloadData|null $data
87+
* @param string $senderId
88+
* @param string $serverKey
8389
*
8490
* @return TopicResponse
8591
*/
86-
public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
92+
public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null, $senderId = null, $serverKey = null)
8793
{
88-
$request = new Request(null, $options, $notification, $data, $topics);
94+
$request = new Request(null, $options, $notification, $data, $topics, $senderId, $serverKey);
8995

9096
$responseGuzzle = $this->post($request);
9197

0 commit comments

Comments
 (0)