8000 Merge branch 'release/1.0.0' · sunaoka/push-notifications-php@c79c1df · GitHub
[go: up one dir, main page]

Skip to content

Commit c79c1df

Browse files
committed
Merge branch 'release/1.0.0'
2 parents bbc5601 + 38a0b81 commit c79c1df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2937
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.gitattributes export-ignore
2+
/.github export-ignore
3+
/.gitignore export-ignore
4+
/CHANGELOG.md export-ignore
5+
/phpstan.neon export-ignore
6+
/phpunit.xml export-ignore
7+
/tests export-ignore

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
test:
11+
name: Test
12+
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
php-version: [
18+
'5.5', '5.6',
19+
'7.0', '7.1', '7.2', '7.3', '7.4',
20+
'8.0', '8.1'
21+
]
22+
23+
steps:
24+
- name: Setup PHP ${{ matrix.php-version }}
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-version }}
28+
29+
- name: Checkout
30+
uses: actions/checkout@v2
31+
32+
- name: Install dependencies
33+
run: composer install --quiet --no-ansi --prefer-dist --no-progress --no-interaction
34+
35+
- name: Run test suite
36+
run: vendor/bin/phpunit --coverage-clover=coverage.xml
37+
38+
- name: Upload coverage to Codecov
39+
uses: codecov/codecov-action@v1
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
42+
file: ./coverage.xml
43+
fail_ci_if_error: true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.build/
2+
/vendor/
3+
/.phpunit.result.cache
4+
/composer.lock

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release Notes
2+
3+
## v1.0.0 (2021-10-12)
4+
5+
- first release.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Norifumi SUNAOKA
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

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Push notifications Library for PHP
2+
3+
[![Latest](https://poser.pugx.org/sunaoka/lpush-notifications-php/v)](https://packagist.org/packages/sunaoka/lpush-notifications-php)
4+
[![License](https://poser.pugx.org/sunaoka/push-notifications-php/license)](https://packagist.org/packages/sunaoka/push-notifications-php)
5+
[![PHP](https://img.shields.io/packagist/php-v/sunaoka/push-notifications-php)](composer.json)
6+
[![Test](https://github.com/sunaoka/push-notifications-php/actions/workflows/test.yml/badge.svg)](https://github.com/sunaoka/push-notifications-php/actions/workflows/test.yml)
7+
[![codecov](https://codecov.io/gh/sunaoka/push-notifications-php/branch/develop/graph/badge.svg)](https://codecov.io/gh/sunaoka/push-notifications-php)
8+
9+
---
10+
11+
## Supported Protocols
12+
13+
| Protocol | Supported | Driver | Options |
14+
| -------------------------- | :-------: | ------------------ | ------------------------- |
15+
| APNs ([Token Based]) | ✓ | `APNs\Token` | `APNs\Token\Option` |
16+
| APNs ([Certificate Based]) | ✓ | `APNs\Certificate` | `APNs\Certificate\Option` |
17+
| APNs ([Binary Provider]) | | | |
18+
| FCM ([HTTP v1]) | ✓ | `FCM\V1` | `FCM\V1\Option` |
19+
| FCM ([Legacy JSON]) | ✓ | `FCM\Json` | `FCM\Json\Option` |
20+
| FCM ([Legacy Plain Text]) | ✓ | `FCM\PlainText` | `FCM\PlainText\Option` |
21+
| FCM ([XMPP]) | | | |
22+
23+
## Installation
24+
25+
```bash
26+
composer require sunaoka/push-notifications-php
27+
```
28+
29+
## Basic Usage
30+
31+
For example, in the case of APNs [Token Based].
32+
33+
```php
34+
<?php
35+
36+
use Sunaoka\PushNotifications\Drivers\APNs;
37+
use Sunaoka\PushNotifications\Pusher;
38+
39+
$payload = [
40+
'aps' => [
41+
'alert' => [
42+
'title' => 'Game Request',
43+
'body' => 'Bob wants to play poker',
44+
],
45+
],
46+
];
47+
48+
$options = new APNs\Token\Option();
49+
$options->payload = $payload;
50+
$options->authKey = 'file:///path/to/key.p8';
51+
$options->keyId = 'ABCDE12345';
52+
$options->teamId = 'ABCDE12345';
53+
$options->topic = 'com.example.app';
54+
55+
$driver = new APNs\Token($options);
56+
57+
$pusher = new Pusher();
58+
$feedback = $pusher->to('Device token')->send($driver);
59+
60+
$result = $feedback->isSuccess('Device token');
61+
if (! $result) {
62+
echo $feedback->failure('Device token');
63+
// BadDeviceToken
64+
}
65+
```
66+
67+
## How to specify options
68+
69+
There are two ways to specify the option.
70+
71+
```php
72+
$options = new APNs\Token\Option();
73+
$options->payload = $payload;
74+
$options->authKey = 'file:///path/to/key.p8';
75+
$options->keyId = 'ABCDE12345';
76+
$options->teamId = 'ABCDE12345';
77+
$options->topic = 'com.example.app';
78+
```
79+
80+
or
81+
82+
```php
83+
$options = new APNs\Token\Option([
84+
'payload' => $payload,
85+
'authKey' => 'file:///path/to/key.p8',
86+
'keyId' => 'ABCDE12345',
87+
'teamId' => 'ABCDE12345',
88+
'topic' => 'com.example.app',
89+
]);
90+
```
91+
92+
## Multicast message
93+
94+
Specify an array of device tokens in `Pusher::to()`.
95+
Then, you can distribute to multiple devices.
96+
97+
```php
98+
$pusher = new Pusher();
99+
$feedback = $pusher->to([
100+
'Device token 1',
101+
'Device token 2',
102+
'Device token 3',
103+
])->send($driver);
104+
```
105+
106+
## How to switch between the production and development environments (only APNs)
107+
108+
This is specified as an argument when creating an instance of `Pusher`.
109+
110+
```php
111+
// Development environment (default)
112+
$pusher = new Pusher(false);
113+
```
114+
115+
```php
116+
// Production environment
117+
$pusher = new Pusher(true);
118+
```
119+
120+
## Feedback
121+
122+
The return value of `Pusher::send()` is a `Feedback` object.
123+
124+
With the `Feedback` object, you can determine whether the notification succeeded or failed.
125+
126+
```php
127+
$pusher = new Pusher();
128+
$feedback = $pusher->to('Device token')->send($driver);
129+
130+
$result = $feedback->isSuccess('Device token');
131+
if ($result) {
132+
echo $feedback->success('Device token');
133+
// 01234567-0123-0123-0123-01234567890A
134+
} else {
135+
echo $feedback->failure('Device token');
136+
// BadDeviceToken
137+
}
138+
```
139+
140+
[Token Based]: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns
141+
[Certificate Based]: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_certificate-based_connection_to_apns
142+
[Binary Provider]: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html
143+
[HTTP v1]: https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
144+
[Legacy JSON]: https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
145+
[Legacy Plain Text]: https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-plain-text
146+
[XMPP]: https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "sunaoka/push-notifications-php",
3+
"description": "Push notifications/messages for mobile devices",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "sunaoka",
9+
"email": "sunaoka@pocari.org"
10+
}
11+
],
12+
"require": {
13+
"php": "^5.5 || ^7.0 || ^8.0",
14+
"ext-json": "*",
15+
"ext-openssl": "*",
16+
"google/apiclient": "^2.8",
17+
"guzzlehttp/guzzle": "^6.0 || ^7.0",
18+
"vlucas/valitron": "^1.4"
19+
},
20+
"require-dev": {
21+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
22+
"roave/security-advisories": "dev-latest"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"Sunaoka\\PushNotifications\\": "./src/"
27+
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Sunaoka\\PushNotifications\\Tests\\": "./tests/"
32+
}
33+
},
34+
"config": {
35+
"optimize-autoloader": true,
36+
"preferred-install": "dist",
37+
"sort-packages": true
38+
},
39+
"minimum-stability": "dev",
40+
"prefer-stable": true,
41+
"scripts": {
42+
"pre-autoload-dump": [
43+
"Google\\Task\\Composer::cleanup"
44+
]
45+
},
46+
"extra": {
47+
"google/apiclient-services": [
48+
"FirebaseCloudMessaging"
49+
]
50+
}
51+
}

phpstan.neon

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
parameters:
2+
3+
paths:
4+
- src
5+
6+
level: 7
7+
8+
checkMissingIterableValueType: false
9+
10+
ignoreErrors:
11+
-
12+
message: '!Parameter #3 \$private_key of function openssl_sign expects!'
13+
path: src/Drivers/APNs/Token.php
14+
-
15+
message: '!Parameter #1 \$string of function base64_encode expects string,!'
16+
path: src/Drivers/APNs/Token.php
17+
-
18+
message: '!Property Sunaoka\\PushNotifications\\Drivers\\FCM\\V1::\$httpClient!'
19+
path: src/Drivers/FCM/V1.php
20+
-
21+
message: '!Parameter #1 \$errors of class!'
22+
path: src/Drivers/DriverOption.php
23+
# -
24+
# message: '!Else branch is unreachable because previous condition is always true!'
25+
# path: src/Drivers/Driver.php

phpunit.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
verbose="true"
6+
colors="true"
7+
>
8+
<testsuites>
9+
<testsuite name="Test">
10+
<directory suffix="Test.php">tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
14+
<filter>
15+
<whitelist processUncoveredFilesFromWhitelist="true">
16+
<directory suffix=".php">src</directory>
17+
</whitelist>
18+
</filter>
19+
</phpunit>

0 commit comments

Comments
 (0)
0