Skip to content

Repository files navigation

Genkgo.Push

Send push messages to Apple, Firebase and Web Push using one interface.

Installation

Requires a PHP version getting security updates. It is installable and autoloadable via Composer as genkgo/push.

Quality

workflow code check

To run the unit tests at the command line, issue phpunit -c tests/. PHPUnit is required.

This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Send Push Messages

<?phpuseGenkgo\Push\Body;
useGenkgo\Push\Firebase\CloudMessaging;
useGenkgo\Push\Firebase\OauthBearerTokenProvider;
useGenkgo\Push\Gateway;
useGenkgo\Push\Message;
useGenkgo\Push\Sender\FirebaseSender;
useGenkgo\Push\Sender\AppleApnSender;
useGenkgo\Push\Sender\WebPushSender;
useGenkgo\Push\Recipient\AndroidDeviceRecipient;
useGenkgo\Push\Recipient\AppleDeviceRecipient;
useGenkgo\Push\Recipient\FirebaseRecipient;
useGenkgo\Push\Recipient\WebRecipient;
useGenkgo\Push\WebPush\PayloadEncryption;
// firebase oauth token$auth = newOauthBearerTokenProvider($guzzleClient, $guzzleHttpFactory, '/link/to/services-account.json');
// construct the gateway, using the different senders$gateway = newGateway([
AppleApnSender::fromToken('/location/to/key.p8', 'keyId', 'teamId', 'bundleId'),
newFirebaseSender(newCloudMessaging($guzzleClient, $guzzleHttpFactory, $auth), 'fcm-project-id'),
newWebPushSender($guzzleClient, $guzzleHttpFactory, newPayloadEncryption(), '/link/to/private-key.pem', '/link/to/public-key.pem', 'mailto:address@domain.com'),
]);
// below message will automatically go to their own specific sender$gateway->send(newMessage(newBody('message content')), newAppleDeviceRecipient('token'));
$gateway->send(newMessage(newBody('message content')), newFirebaseRecipient('token'));
$gateway->send(newMessage(newBody('message content')), newWebRecipient('https://endpoint', 'keys.auth', 'keys.p256dh'));

Contributing

  • Found a bug? Please try to solve it yourself first and issue a pull request. If you are not able to fix it, at least give a clear description what goes wrong. We will have a look when there is time.
  • Want to see a feature added, issue a pull request and see what happens. You could also file a bug of the missing feature and we can discuss how to implement it.

About

Send push messages to Apple, Firebase and Web Push using one interface

Topics

Resources

Stars

13 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages