Download the PHP package raneomik/nette-pwa without Composer

On this page you can find all versions of the php package raneomik/nette-pwa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package nette-pwa

Nette PWA Extension

.github/workflows/ci.yml .github/workflows/coverage.yml codecov Mutation Testing Mutation testing badge

Work In Progress

📲 Nette extension for Progressive Web Apps: the web app manifest written in NEON, a service worker, and Web Push notifications (optional) with minishlink/web-push.

Requirements

Package For
latte/latte {pwaHead()}
nette/assets versioned icon URLs (src: 'img:icon')
minishlink/web-push, symfony/http-client, nyholm/psr7 Web Push (ext-gmp strongly advised)
nette/database default subscription storage
contributte/translation a subscription keeps the locale of its page
tracy/tracy debug panel

Getting started

Register the extension and describe the manifest:

Link it from your layout:

The manifest is now served at /manifest.webmanifest & the service worker at /sw.js.

Enable Web Push

Then:

  1. declare a TopicAuthorizer service (required);
  2. create the subscriptions table;
  3. add an opt-in button and the client script:

quickstart on dev :

prefer copy-paste-adapt :

The button is a toggle: clicked again, it turns notifications off (aria-pressed="true" while on).

Send a notification

Topics work as with Mercure: a browser subscribes to topics, you send to a topic without knowing who listens.

A browser subscribes in the locale of its page: <html lang> when contributte/translation knows it, the translator's current locale otherwise, en without a translator. Pass a closure to send each one in its language: it is called once per locale of the listeners.

Expired subscriptions (404/410) are removed; the other failures are returned for you to log.

Authorize topics

The compilation fails without a TopicAuthorizer service: "allow all" would let anyone receive anyone's pushes.

Store subscriptions

Table of the default storage (nette/database):

Your own Raneomik\NettePWA\Push\SubscriptionStorage service replaces it.

Customize the service worker

Copy assets/sw.js, add what you need (offline cache...), keep its push, pushsubscriptionchange and notificationclick listeners:

Test locally

Reference

Configuration

Option Default Description
manifest.name required
manifest.shortName, description, id, orientation, lang, backgroundColor, themeColor –
manifest.startUrl, manifest.scope /
manifest.display standalone fullscreen, standalone, minimal-ui, browser
manifest.icons[] – src (required: Nette Assets ref or URL), sizes, type, purpose
manifest.extra – any other manifest member, as is (shortcuts, screenshots...)
serviceWorker package assets/sw.js file served at /sw.js
push null no push services, no subscribe route
push.vapid.publicKey, privateKey required dynamic parameters allowed
push.vapid.subject %baseUrl% mailto: or https://
push.ttl 2419200 seconds the push service keeps a push for an offline device
push.urgency – very-low, low, normal, high
push.timeout 3.0 seconds, per push service call
push.table push_subscriptions default storage only
push.pushServices FCM, Mozilla, Apple, Windows endpoint hosts accepted
push.subscribeAtPath pwa/push/subscribe relative to the base path
debugger %debugMode% Tracy panel

Routes

Prepended to the app's RouteList. The manifest and the service worker are served with Cache-Control: no-cache + ETag.

RouteMethod
/manifest.webmanifestGET
/sw.jsGET
/pwa/push/subscribePOSTsubscribe to topics
PUTsubscription rotated by the browser: topics move to the new endpoint
DELETEunsubscribe

Latte

{pwaHead()}: manifest link, theme-color, and the <meta> tags read by push-client.js.

Button attributes (push-client.js)

Attribute Value
data-pwa-push topics, space separated; the browser listens to those of all the buttons of the page (20 at most, 255 characters each)
data-pwa-on label while on (default 🔔 Notifications on)
data-pwa-off label while off (default: the button's own text)
data-pwa-blocked label when the permission is denied (default 🔕 Notifications blocked)
data-pwa-error label when the subscription fails (default 🔕 Notifications unavailable)
data-pwa-install label on iOS outside the installed app (default 📲 Add to Home Screen to get notifications)

The script sets aria-pressed (true while on) and disabled (blocked, error, install). Without VAPID key or browser support, the buttons are hidden.

PHP

Service
Manifest\ManifestProvider ->manifest: typed, read-only Manifest\Value\Manifest (Icon, Display enum)
Push\PushSender send(string\|array $topics, Notification\|Closure $notification): array of failures (MessageSentReport)
Push\Notification title, body, url (opened on click), tag (replaces a previous one, default: the url)
Push\TopicAuthorizer isAllowed(string $topic): bool, yours to implement
Push\SubscriptionStorage save(), find(), remove(), replace()

How it works

Debugging

In debug mode, a PWA Tracy panel shows what the browser DevTools cannot:

The tab counts the pushes sent and, in red, the errors. Outside debug mode, nothing is recorded.

Development

Resources

License

MIT


All versions of nette-pwa with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
nette/application Version ^3.2
nette/di Version ^3.2
nette/http Version ^3.3
nette/schema Version ^1.4
nette/utils Version ^4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package raneomik/nette-pwa contains the following files

Loading the files please wait ...