Skip to content

Commit 426e515

Browse files
committed
init
0 parents  commit 426e515

18 files changed

+2250
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vendor
2+
.project
3+
.buildpath
4+
.settings
5+
.idea

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 sngrl
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# PHP Firebase Cloud Messaging
2+
PHP API for Firebase Cloud Messaging from Google.
3+
4+
Currently this app server library only supports sending Messages/Notifications via HTTP.
5+
6+
See original Firebase docs: https://firebase.google.com/docs/
7+
8+
#Setup
9+
Install via Composer:
10+
```
11+
composer require sngrl/php-firebase-cloud-messaging
12+
}
13+
```
14+
15+
Or add this to your composer.json and run "composer update":
16+
17+
```
18+
"require": {
19+
"sngrl/php-firebase-cloud-messaging": "dev-master"
20+
}
21+
```
22+
23+
#Send message to Device
24+
```
25+
use sngrl\PhpFirebaseCloudMessaging\Client;
26+
use sngrl\PhpFirebaseCloudMessaging\Message;
27+
use sngrl\PhpFirebaseCloudMessaging\Recipient\Device;
28+
use sngrl\PhpFirebaseCloudMessaging\Notification;
29+
30+
$server_key = '_YOUR_SERVER_KEY_';
31+
$client = new Client();
32+
$client->setApiKey($server_key);
33+
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());
34+
35+
$message = new Message();
36+
$message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_'));
37+
$message
38+
->setNotification(new Notification('some title', 'some body'))
39+
->setData(['key' => 'value'])
40+
;
41+
42+
$response = $client->send($message);
43+
var_dump($response->getStatusCode());
44+
```
45+
46+
#Send message to Topic
47+
Currently sending to topics only supports a single topic as recipient. Mutliple topic as outlined
48+
in the google docs don't seem to work, yet.
49+
```
50+
use sngrl\PhpFirebaseCloudMessaging\Client;
51+
use sngrl\PhpFirebaseCloudMessaging\Message;
52+
use sngrl\PhpFirebaseCloudMessaging\Recipient\Topic;
53+
use sngrl\PhpFirebaseCloudMessaging\Notification;
54+
55+
$server_key = '_YOUR_SERVER_KEY_';
56+
$client = new Client();
57+
$client->setserver_key($server_key);
58+
$client->injectGuzzleHttpClient(new \GuzzleHttp\Client());
59+
60+
$message = new Message();
61+
$message->addRecipient(new Topic('_YOUR_TOPIC_'));
62+
$message
63+
->setNotification(new Notification('some title', 'some body'))
64+
->setData(['key' => 'value'])
65+
;
66+
67+
$response = $client->send($message);
68+
var_dump($response->getStatusCode());
69+
```

composer.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "sngrl/php-firebase-cloud-messaging",
3+
"description": "PHP API for Firebase Cloud Messaging from Google",
4+
"license": "MIT",
5+
"keywords": ["PHP","FCM","Google","Firebase","Cloud","Notifications","Android","iOS","Chrome"],
6+
"homepage": "https://github.com/sngrl/php-firebase-cloud-messaging",
7+
"authors": [
8+
{
9+
"name": "Sngrl",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"guzzlehttp/guzzle": "*",
15+
"php": ">=5.5"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "*",
19+
"mockery/mockery" : "*"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"sngrl\\php-firebase-cloud-messaging\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"sngrl\\php-firebase-cloud-messaging\\Tests\\": "tests/"
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)