Download the PHP package ez-php/push without Composer
On this page you can find all versions of the php package ez-php/push. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package push
Short Description Mobile push notifications (APNS, FCM) as an ez-php/notification channel
License MIT
Homepage https://github.com/ez-php/push
Informations about the package push
ez-php/push
Mobile push notifications for ez-php applications. Delivers a PushMessage to a
device token through a pluggable driver — APNS (Apple, HTTP/2 provider API with
token-based .p8 authentication) or FCM (Firebase Cloud Messaging, HTTP v1 API
with service-account OAuth2), or Web Push (browsers, VAPID + RFC 8291 encryption) — plus Null and Array drivers for local development
and testing.
Device-token storage, invalid-token pruning, and topic/channel subscription management are application-layer concerns — this package only delivers a message to a token you already have.
Installation
Requires ez-php/http-client to be registered first — the apns and fcm
drivers resolve HttpClient from the container.
Quick Start
Register the providers in provider/modules.php:
Add configuration to config/push.php:
Send a push notification from anywhere:
Or fan out to many tokens without one failure blocking the rest:
Drivers
| Driver | PUSH_DRIVER |
Description |
|---|---|---|
| Null | null |
Silently discards all notifications (default) |
| Array | array |
Stores notifications in memory — designed for testing |
| APNS | apns |
Apple Push Notification service, HTTP/2 provider API |
| FCM | fcm |
Firebase Cloud Messaging, HTTP v1 API |
| Web Push | webpush |
Browser push (VAPID), encrypted per RFC 8291 |
APNS Driver
PUSH_APNS_PRIVATE_KEY is the PEM contents of the .p8 authentication key
downloaded from the Apple Developer portal. The driver signs an ES256 provider
JWT from it and reuses that JWT across requests for up to 50 minutes, per
Apple's guidance. Set PUSH_APNS_SANDBOX=true to target the sandbox APNS host
during development.
FCM Driver
PUSH_FCM_CLIENT_EMAIL and PUSH_FCM_PRIVATE_KEY come from a Firebase
service-account JSON key (Project Settings → Service Accounts → Generate new
private key). The driver exchanges an RS256-signed JWT-bearer assertion for an
OAuth2 access token and caches it for its ~1-hour lifetime.
Web Push Driver
PUSH_WEBPUSH_PRIVATE_KEY is your VAPID key: a P-256 EC private key in PEM form
(openssl ecparam -genkey -name prime256v1 -noout). Give the browser the matching
public key when subscribing — WebPushDriver::vapidPublicKey($pem) returns it in the
base64url form pushManager.subscribe({applicationServerKey}) expects.
The "device token" is the browser's PushSubscription as JSON — store
JSON.stringify(subscription) and pass it to Push::send():
The service worker receives {"title", "body", "data", "badge"?, "sound"?}. Payloads are
encrypted per RFC 8291 (max 4079 bytes). A 404/410 from the push service means the
subscription is gone — a PushException is raised; dropping the subscription is up to you.
Array Driver (for Testing)
Static Facade
Push is a static facade backed by a Pusher singleton:
| Method | Description |
|---|---|
Push::send(string $token, PushMessage $message) |
Deliver to one device token |
Push::sendToMany(list<string> $tokens, PushMessage $message) |
Deliver to many tokens, returning a token => PushException\|null map |
Push::setPusher(Pusher) |
Wire the singleton (done by PushServiceProvider) |
Push::resetPusher() |
Reset to null — call in test tearDown() |
Throws RuntimeException if called before setPusher().
Custom Driver
Implement PushDriverInterface to add a custom backend:
Bind it in a service provider:
Exceptions
PushException (extends RuntimeException) is the base exception for this
package — thrown on an invalid signing key or a non-2xx response from APNS/FCM.
Push::send() / Push::sendToMany() throw plain RuntimeException if called
before the pusher is set.
License
MIT
All versions of push with dependencies
ext-openssl Version *
ez-php/contracts Version ^2.7.0
ez-php/http-client Version ^2.7.0