cmnty / push
Web Push library for PHP
Installs: 13 456
Dependents: 1
Suggesters: 0
Security: 0
Stars: 12
Watchers: 5
Forks: 3
Open Issues: 1
Requires
- php: ~5.6|~7.0
- ext-crypto: *
- guzzlehttp/guzzle: ~6.2.1
- mdanter/ecc: ~0.4.0
- spomky-labs/base64url: ~1.0
This package is not auto-updated.
Last update: 2022-04-30 06:25:12 UTC
README
Web Push library for PHP
Instalation
Require the library with composer:
composer require cmnty/push
This library supports both ext-crypto
and lib-openssl
for it's encryption needs.
While a php fallback can be provided by spomky-labs/php-aes-gcm
it is advised to use that only as a last resort.
Usage
<?php use Cmnty\Push\AggregatePushService; use Cmnty\Push\Client; use Cmnty\Push\Crypto\AuthenticationSecret; use Cmnty\Push\Crypto\PublicKey; use Cmnty\Push\EndPoint; use Cmnty\Push\GooglePushService; use Cmnty\Push\MozillaPushService; use Cmnty\Push\Notification; use Cmnty\Push\PushServiceRegistry; use Cmnty\Push\Subscription; $notification = new Notification('Hello', 'World!'); $subscription = new Subscription( new Endpoint('...'), new PublicKey::createFromBase64UrlEncodedString('...'), new AuthenticationSecret::createFromBase64UrlEncodedString('...') ); $pushServiceRegistry = new PushServiceRegistry(); $pushServiceRegistry->addPushService(new GooglePushService('API Key')); $pushServiceRegistry->addPushService(new MozillaPushService()); $pushService = new AggregatePushService($pushServiceRegistry); $client = new Client($pushService); $client->pushNotification($notification, $subscription);
By default, the Cmnty\Push\Crypto\AggregateCrypt
class is used to encrypt the notification.
This class tries to encrypt the notification using third party libraries or extensions in the following order:
- Encrypt using
ext-crypto
implemented byCmnty\Push\Crypto\ExtCryptoCrypt
- Encrypt using
lib-openssl
implemented byCmnty\Push\Crypto\OpenSSLCrypt
- Encrypt using native php implemented by
Cmnty\Push\Crypto\SpomkyLabsCrypt
usingspomky-labs/php-aes-gcm
You can also force a certain library or extension to be used by passing it to the PushClient:
<?php use Cmnty\Push\Client; use Cmnty\Push\Crypto\Cryptograph; use Cmnty\Push\Crypto\ExtCryptoCrypt; $pushService = ...; $cryptograph = new Cryptograph(new ExtCryptoCrypt()); $client = new Client($pushService, null, $cryptograph);
If required, you can also provide your own implementation by implementing the Cmnty\Push\Crypto\Crypt
interface.
Framework Integration
- Symfony: cmnty/push-bundle
Credits
License
The MIT License (MIT). Please see License File for more information.