Code Monkey home page Code Monkey logo

php-push's Introduction

cmnty/push

Latest Version on Packagist Software License Total Downloads

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 by Cmnty\Push\Crypto\ExtCryptoCrypt
  • Encrypt using lib-openssl implemented by Cmnty\Push\Crypto\OpenSSLCrypt
  • Encrypt using native php implemented by Cmnty\Push\Crypto\SpomkyLabsCrypt using spomky-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

Credits

License

The MIT License (MIT). Please see License File for more information.

php-push's People

Contributors

johanderuijter avatar peternijssen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.