minishlink / web-push-bundle
Symfony Bundle around the WebPush library
Package info
github.com/Minishlink/web-push-bundle
Type:symfony-bundle
pkg:composer/minishlink/web-push-bundle
Requires
- php: ^8.2
- minishlink/web-push: ^11.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.9.2
- matthiasnoback/symfony-dependency-injection-test: ^4.2.1|^5.0
- phpunit/phpunit: ^10.0|^11.0
- symfony/framework-bundle: ^6.4|^7.0
- symfony/phpunit-bridge: ^6.4|^7.0
README
This bundle provides a simple integration of the WebPush library.
Usage
Web Push sends notifications to endpoints which server delivers web push notifications as described in the Web Push API specification.
<?php /** @var \Minishlink\WebPush\WebPush */ $webPush = $this->container->get('minishlink_web_push');
The bundle provides a new minishlink_web_push service that returns an instance of Minishlink\WebPush\WebPush.
For more info on what you can do with $webPush, check Minishlink/web-push.
Installation
composer require minishlink/web-push-bundle- Enable the bundle in your
app/AppKernel.php.
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Minishlink\Bundle\WebPushBundle\MinishlinkWebPushBundle(), // ... ); }
Configuration
Here is the default configuration, you may change it in your app/config/config.yml.
minishlink_web_push: VAPID: subject: https://yoursite.com # can be an URL or a mailto: publicKey: ~88 chars # uncompressed public key P-256 encoded in Base64-URL privateKey: ~44 chars # the secret multiplier of the private key encoded in Base64-URL pemFile: path/to/pem # if you have a PEM file and can link to it on your filesystem pem: pemFileContent # if you have a PEM file and want to hardcode its content ttl: 2419200 # Time to Live of notifications in seconds urgency: ~ # can be very-low / low / normal / high topic: ~ # default identifier for your notifications http_client: ~ # service id of a PSR-18 client to use (e.g. a pre-configured Guzzle client service). Defaults to auto-discovering one, e.g. Guzzle if installed. automatic_padding: true # pad messages automatically for better security (against more bandwith usage)
Customizing the HTTP client
Since minishlink/web-push v11, the library depends on PSR-18 instead of
being tied to Guzzle. Configure your PSR-18 client instance directly and either register it under Psr\Http\Client\ClientInterface (picked up automatically) or point
http_client at its service id:
minishlink_web_push: http_client: my_configured_http_client
services: my_configured_http_client: class: GuzzleHttp\Client arguments: - timeout: 20