Documentation

WebPushAdapter
in package

FinalYes

Thin compatibility layer over minishlink/web-push.

Keeps the same public method names and adds convenient helpers/templates.

Table of Contents

Properties

$inner  : WebPush

Methods

__call()  : mixed
Dynamically call methods on the inner notification service
__construct()  : mixed
Create a new notification service instance
flush()  : Generator
Flush the notification queue with optional batch processing
flushPooled()  : Generator
Flush the pooled notification queue with optional batch processing
generateVapidKeys()  : array<string|int, mixed>
Returns stdClass with: $keys->public $keys->private
getInner()  : WebPush
Get the inner native web push instance
payloadChatMessage()  : string
Build a chat message notification payload
payloadError()  : string
Payload builder for error notifications.
payloadImageText()  : string
Build an image + text notification payload
payloadMarketing()  : string
Build a marketing notification payload
payloadOrderStatusChanged()  : string
Build an order status change notification payload
payloadRich()  : string
Build a rich notification payload with custom data
payloadSuccess()  : string
Build a success notification payload
payloadSystem()  : string
Build a system notification payload
payloadText()  : string
Build a basic text notification payload
payloadTextWithDescription()  : string
Build a text notification with description payload
payloadTextWithUrl()  : string
Build a text notification with URL payload
payloadWarning()  : string
Build a warning notification payload
queueImageText()  : self
Queue an image + text notification
queueNotification()  : self
Queue a notification for delivery to a subscription
queueText()  : self
Queue a text-only notification
queueTextWithDescription()  : self
Queue a text notification with description
queueTextWithUrl()  : self
Queue a text notification with URL
sendImageText()  : MessageSentReport
Send an image + text notification
sendOneNotification()  : MessageSentReport
Send a single notification to a subscription
sendText()  : MessageSentReport
Send a text-only notification
sendTextWithDescription()  : MessageSentReport
Send a text notification with description
sendTextWithUrl()  : MessageSentReport
Send a text notification with URL
setAutomaticPadding()  : self
Accepts bool or int just like the library's automatic padding concept.
setDefaultOptions()  : self
Set default options for all notifications sent by this service
setReuseVAPIDHeaders()  : self
Set whether VAPID headers should be reused for multiple notifications
subscription()  : Subscription
Create a new subscription with the given data
encodePayload()  : string
Encode payload data into JSON string with error handling

Properties

Methods

__call()

Dynamically call methods on the inner notification service

public __call(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string

The name of the method to call

$arguments : array<string|int, mixed>

The arguments to pass to the method

Return values
mixed

The result of the method call

__construct()

Create a new notification service instance

public __construct(mixed ...$args) : mixed
Parameters
$args : mixed

Arguments to pass to the native web push constructor

flush()

Flush the notification queue with optional batch processing

public flush([int|null $batchSize = null ]) : Generator
Parameters
$batchSize : int|null = null

The maximum number of notifications to process in this batch (null for all)

Return values
Generator

Generator that yields processed notifications

flushPooled()

Flush the pooled notification queue with optional batch processing

public flushPooled([int|null $batchSize = null ]) : Generator
Parameters
$batchSize : int|null = null

The maximum number of notifications to process in this batch (null for all)

Return values
Generator

Generator that yields processed notifications

generateVapidKeys()

Returns stdClass with: $keys->public $keys->private

public static generateVapidKeys() : array<string|int, mixed>
Return values
array<string|int, mixed>

getInner()

Get the inner native web push instance

public getInner() : WebPush
Return values
WebPush

The native web push instance

payloadChatMessage()

Build a chat message notification payload

public static payloadChatMessage(string $title, string $body[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$url : string|null = null

Optional URL to open when clicked

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadError()

Payload builder for error notifications.

public static payloadError(string $title, string $body[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string

This method creates a JSON payload specifically designed for error notifications. It extends the base notification structure with error-specific fields and default values, making it suitable for system alerts, error reporting, or user-facing error messages.

Parameters
$title : string

The title of the error notification

$body : string

The main content/message of the error

$url : string|null = null

Optional URL to open when the notification is clicked (e.g., error details page)

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload string ready for transmission

payloadImageText()

Build an image + text notification payload

public static payloadImageText(string $title, string $body, string $imageUrl[, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$imageUrl : string

The URL of the image to display

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadMarketing()

Build a marketing notification payload

public static payloadMarketing(string $title, string $body[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$url : string|null = null

Optional URL to open when clicked

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadOrderStatusChanged()

Build an order status change notification payload

public static payloadOrderStatusChanged(string $orderId, string $oldStatus, string $newStatus[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$orderId : string

The order identifier

$oldStatus : string

The previous order status

$newStatus : string

The new order status

$url : string|null = null

Optional URL to open when clicked

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadRich()

Build a rich notification payload with custom data

public static payloadRich(array<string|int, mixed> $data) : string
Parameters
$data : array<string|int, mixed>

The custom data for the rich notification

Return values
string

JSON encoded payload

payloadSuccess()

Build a success notification payload

public static payloadSuccess(string $title, string $body[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$url : string|null = null

Optional URL to open when clicked

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadSystem()

Build a system notification payload

public static payloadSystem(string $title, string $body[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$url : string|null = null

Optional URL to open when clicked

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadText()

Build a basic text notification payload

public static payloadText(string $title, string $body[, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadTextWithDescription()

Build a text notification with description payload

public static payloadTextWithDescription(string $title, string $body, string $description[, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$description : string

The description text

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadTextWithUrl()

Build a text notification with URL payload

public static payloadTextWithUrl(string $title, string $body, string $url[, string|null $description = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$url : string

The URL to open when clicked

$description : string|null = null

Optional description text

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

payloadWarning()

Build a warning notification payload

public static payloadWarning(string $title, string $body[, string|null $url = null ][, array<string|int, mixed> $extra = [] ]) : string
Parameters
$title : string

The title of the notification

$body : string

The main content of the notification

$url : string|null = null

Optional URL to open when clicked

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
string

JSON encoded payload

queueImageText()

Queue an image + text notification

public queueImageText(Subscription $subscription, string $title, string $body, string $imageUrl[, array<string|int, mixed> $extra = [] ]) : self
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$imageUrl : string

The URL of the image to display

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
self

Fluent interface for method chaining

queueNotification()

Queue a notification for delivery to a subscription

public queueNotification(Subscription $subscription[, string|null $payload = null ]) : self
Parameters
$subscription : Subscription

The subscription to send notification to

$payload : string|null = null

The notification payload to queue (null means use default)

Return values
self

Fluent interface for method chaining

queueText()

Queue a text-only notification

public queueText(Subscription $subscription, string $title, string $body[, array<string|int, mixed> $extra = [] ]) : self
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
self

Fluent interface for method chaining

queueTextWithDescription()

Queue a text notification with description

public queueTextWithDescription(Subscription $subscription, string $title, string $body, string $description[, array<string|int, mixed> $extra = [] ]) : self
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$description : string

The description text

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
self

Fluent interface for method chaining

queueTextWithUrl()

Queue a text notification with URL

public queueTextWithUrl(Subscription $subscription, string $title, string $body, string $url[, string|null $description = null ][, array<string|int, mixed> $extra = [] ]) : self
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$url : string

The URL to open when clicked

$description : string|null = null

Optional description text

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

Return values
self

Fluent interface for method chaining

sendImageText()

Send an image + text notification

public sendImageText(Subscription $subscription, string $title, string $body, string $imageUrl[, array<string|int, mixed> $extra = [] ][, array<string|int, mixed> $options = [] ]) : MessageSentReport
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$imageUrl : string

The URL of the image to display

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

$options : array<string|int, mixed> = []

Optional configuration for sending

Return values
MessageSentReport

Report of the message delivery

sendOneNotification()

Send a single notification to a subscription

public sendOneNotification(Subscription $subscription[, string|null $payload = null ][, array<string|int, mixed> $options = [] ]) : MessageSentReport
Parameters
$subscription : Subscription

The subscription to send notification to

$payload : string|null = null

The notification payload to send (null means use default)

$options : array<string|int, mixed> = []

Additional options for sending the notification

Return values
MessageSentReport

Report of the message delivery

sendText()

Send a text-only notification

public sendText(Subscription $subscription, string $title, string $body[, array<string|int, mixed> $extra = [] ][, array<string|int, mixed> $options = [] ]) : MessageSentReport
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

$options : array<string|int, mixed> = []

Optional configuration for sending

Return values
MessageSentReport

Report of the message delivery

sendTextWithDescription()

Send a text notification with description

public sendTextWithDescription(Subscription $subscription, string $title, string $body, string $description[, array<string|int, mixed> $extra = [] ][, array<string|int, mixed> $options = [] ]) : MessageSentReport
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$description : string

The description text

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

$options : array<string|int, mixed> = []

Optional configuration for sending

Return values
MessageSentReport

Report of the message delivery

sendTextWithUrl()

Send a text notification with URL

public sendTextWithUrl(Subscription $subscription, string $title, string $body, string $url[, string|null $description = null ][, array<string|int, mixed> $extra = [] ][, array<string|int, mixed> $options = [] ]) : MessageSentReport
Parameters
$subscription : Subscription

The subscription to send notification to

$title : string

The title of the notification

$body : string

The main content of the notification

$url : string

The URL to open when clicked

$description : string|null = null

Optional description text

$extra : array<string|int, mixed> = []

Additional fields to include in the payload

$options : array<string|int, mixed> = []

Optional configuration for sending

Return values
MessageSentReport

Report of the message delivery

setAutomaticPadding()

Accepts bool or int just like the library's automatic padding concept.

public setAutomaticPadding(bool|int $automaticPadding) : self

Set whether automatic padding should be applied to notifications

Parameters
$automaticPadding : bool|int

Whether to enable automatic padding (true/false or 1/0)

Return values
self

Fluent interface for method chaining

setDefaultOptions()

Set default options for all notifications sent by this service

public setDefaultOptions(array<string|int, mixed> $defaultOptions) : self
Parameters
$defaultOptions : array<string|int, mixed>

The default options to use

Return values
self

Fluent interface for method chaining

setReuseVAPIDHeaders()

Set whether VAPID headers should be reused for multiple notifications

public setReuseVAPIDHeaders([bool $reuse = true ]) : self
Parameters
$reuse : bool = true

Whether to reuse VAPID headers (defaults to true)

Return values
self

Fluent interface for method chaining

subscription()

Create a new subscription with the given data

public static subscription(array<string|int, mixed> $data) : Subscription
Parameters
$data : array<string|int, mixed>

The subscription data

Return values
Subscription

The created subscription

encodePayload()

Encode payload data into JSON string with error handling

private static encodePayload(array<string|int, mixed> $data) : string
Parameters
$data : array<string|int, mixed>

The data to encode

Return values
string

JSON encoded string

On this page

Search results