PHP code example of cmnty / push

1. Go to this page and download the library: Download cmnty/push library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cmnty / push example snippets




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);



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);