LogoLogo
3.1.x
3.1.x
  • Web-Push
  • Requirements
  • Fluent Syntax
  • Contributing
  • License
  • Common Concepts
    • Overview
    • The Subscription
    • The Notification
    • The Status Report
    • VAPID
  • The Library
    • Installation
    • The Extension Manager
    • The Web Push Service
  • The Symfony Bundle
    • Installation
    • Configuration
    • The Web Push Service
    • Doctrine
    • Example
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. The Library

The Web Push Service

PreviousThe Extension ManagerNextInstallation

Was this helpful?

The WebPush object requires a and an .

use Symfony\Component\HttpClient\HttpClient;
use WebPush\WebPush;

$client = HttpClient::create();

$service = new WebPush($client, $extensionManager);

The service is now ready to send Notifications to the Subscriptions. The StatusReport object that is returned .

<?php

use WebPush\Subscription;
use WebPush\Notification;

$subscription = Subscription::createFromString('{"endpoint":"https://updates.push.services.mozilla.com/wpush/v2/AAAAAAAA[…]AAAAAAAAA","keys":{"auth":"XXXXXXXXXXXXXX","p256dh":"YYYYYYYY[…]YYYYYYYYYYYYY"}}');
$notification = Notification::create()
    ->withPayload('Hello world')
;

$statusReport = $service->send($notification, $subscription);

In this example, we load the Subscription object from a string, but usually to retrieve the Subscription objects from a database or a dedicated storage.

HTTP Client
Extension Manager
is explained here