Skip to content

Notification

Viames Marino edited this page Feb 22, 2026 · 1 revision

Pair framework: Notification

Pair\Push\Notification is the payload value object for web push messages.

Constructor

new Notification(
    string $title,
    string $body,
    ?string $url = null,
    ?string $icon = null,
    ?string $tag = null,
    array $data = []
)

Main method

toPayload(): array

Builds service-worker-compatible payload:

  • always includes title, body
  • adds icon and tag when set
  • merges custom data
  • injects url into data.url when provided

Implementation examples

Basic notification:

$notification = new \Pair\Push\Notification(
    'New message',
    'You have a new message.'
);

With deep-link and metadata:

$notification = new \Pair\Push\Notification(
    'Order shipped',
    'Order #123 has been shipped.',
    '/orders/123',
    '/img/push/order.png',
    'order-123',
    ['orderId' => 123, 'type' => 'shipping-update']
);

Payload sent to push sender:

$payload = $notification->toPayload();

End-to-end example with dispatcher

$dispatcher = new \Pair\Push\PushDispatcher();
$results = $dispatcher->sendToUser($userId, $notification);

See also: PushDispatcher, DeliveryResult, WebPushSender.

Clone this wiki locally