PHP code example of raneomik / nette-pwa

1. Go to this page and download the library: Download raneomik/nette-pwa 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/ */

    

raneomik / nette-pwa example snippets


use Raneomik\NettePWA\Push\Notification;

$failures = $pushSender->send("player/{$id}", new Notification('Bob joined', 'Time to play!', url: $link));
$pushSender->send(['room/abc', 'room/def'], $notification); // each browser once

$pushSender->send("player/{$id}", fn (string $locale) => new Notification(
    $translator->translate('game.joined', ['name' => 'Bob'], locale: $locale),
));

final class TopicAccess implements Raneomik\NettePWA\Push\TopicAuthorizer
{
    public function __construct(private Nette\Security\User $user) {}

    public function isAllowed(string $topic): bool
    {
        return str_starts_with($topic, 'room/') || $topic === "player/{$this->user->getId()}";
    }
}

$manifest = $manifestProvider->manifest;
$manifest->themeColor;          // ?string
$manifest->display;             // Display::Standalone
$manifest->icons[0]->src;       // 'img:icon', as configured (the JSON gets the asset URL)
$manifest->extra['categories']; // the extra members stay raw
bash
composer ire "vendor/autoload.php"; print_r(Minishlink\WebPush\VAPID::createVapidKeys());'