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

Commit 7edc3e4

Browse files
committed
Merge #21 - Multiple FCM Account Support
Pull-request: #21
2 parents 959db26 + 0333636 commit 7edc3e4

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Laravel-FCM (maintained version of the abandonned "official" repository)
1+
# Laravel-FCM (maintained and enhanced version of the abandonned "official" repository)
22

33
![Run tests](https://github.com/code-lts/Laravel-FCM/workflows/Run%20tests/badge.svg?branch=main)
44
[![Coverage Status](https://codecov.io/gh/code-lts/laravel-fcm/branch/main/graph/badge.svg)](https://codecov.io/gh/code-lts/laravel-fcm)
@@ -105,7 +105,7 @@ Copy the config file ```fcm.php``` manually from the directory ```/vendor/code-l
105105

106106
In your `.env` file, add the server key and the secret key for the Firebase Cloud Messaging:
107107

108-
```php
108+
```env
109109
FCM_SERVER_KEY=my_secret_server_key
110110
FCM_SENDER_ID=my_secret_sender_id
111111
```
@@ -275,7 +275,7 @@ $topicResponse = FCM::sendToTopic($topic, null, $notification, null);
275275

276276
$topicResponse->isSuccess();
277277
$topicResponse->shouldRetry();
278-
$topicResponse->error());
278+
$topicResponse->error();
279279

280280
```
281281

@@ -310,8 +310,6 @@ $key = FCMTopic::unsubscribeTopic($topic_id, $recipients_tokens);
310310
#### Sending a Notification to a Group
311311

312312
```php
313-
314-
315313
$notificationBuilder = new PayloadNotificationBuilder('my title');
316314
$notificationBuilder->setBody('Hello world')
317315
->setSound('default');

src/Request/Request.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ class Request extends BaseRequest
5252
* @param PayloadNotification $notification
5353
* @param PayloadData $data
5454
* @param Topics|null $topic
55+
* @param string|null $serverKey (optional) The server key
56+
* @param string|null $senderId (optional) The sender Id
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, string $serverKey = null, string $senderId = null)
5759
{
58-
parent::__construct();
60+
parent::__construct($serverKey, $senderId);
5961

6062
$this->to = $to;
6163
$this->options = $options;

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|null $serverKey (optional) The server key
27+
* @param string|null $senderId (optional) The sender Id
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, string $serverKey = null, string $senderId = 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, $serverKey, $senderId);
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|null $serverKey (optional) The server key
67+
* @param string|null $senderId (optional) The sender Id
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, string $serverKey = null, string $senderId = null)
6872
{
69-
$request = new Request($notificationKey, $options, $notification, $data);
73+
$request = new Request($notificationKey, $options, $notification, $data, null, $serverKey, $senderId);
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|null $serverKey (optional) The server key
88+
* @param string|null $senderId (optional) The sender Id
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, string $serverKey = null, string $senderId = null)
8793
{
88-
$request = new Request(null, $options, $notification, $data, $topics);
94+
$request = new Request(null, $options, $notification, $data, $topics, $serverKey, $senderId);
8995

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

0 commit comments

Comments
 (0)