MessagingNotificationProviderFirebase

Reference for the MessagingNotificationProviderFirebase module: send push notifications through Firebase Cloud Messaging, and store the device tokens that belong to each member. It registers itself as a notification provider with the Messaging module.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

MessagingNotificationProviderFirebase

Send a push notification to a single device through the Firebase Cloud Messaging HTTP API, using the server key from the module configuration.

Functions

Send

MessagingNotificationProviderFirebase::Send(string $deviceToken, string $title, string $body, ?array $optionalData = null): void

Send a push notification via Firebase Cloud Messaging. Builds the message payload, posts it to the Firebase Cloud Messaging endpoint with the configured server key, and throws when the request or the response reports a failure.

NameTypeDescription
$deviceTokenstringDevice FCM token.
$titlestringNotification title.
$bodystringNotification body text.
$optionalData?arrayOptional data payload; values are sent as strings.

Returns void

MessagingNotificationFirebaseDeviceDatabase

Store and read the Firebase device tokens registered for members: register or refresh a token, list a member's tokens, look one up by id, and delete one by token.

DeleteByToken

MessagingNotificationFirebaseDeviceDatabase::DeleteByToken(string $token): void

Delete a device token.

NameTypeDescription
$tokenstringThe FCM device token to delete.

Returns void

GetById

MessagingNotificationFirebaseDeviceDatabase::GetById(int $id): MessagingNotificationFirebaseDeviceData

Get device by id.

NameTypeDescription
$idintThe device id.

Returns MessagingNotificationFirebaseDeviceData The device.

GetTokensForMember

MessagingNotificationFirebaseDeviceDatabase::GetTokensForMember(int $memberId): array

Get all device tokens for a member, most recently used first.

NameTypeDescription
$memberIdintThe member id.

Returns array A list of MessagingNotificationFirebaseDeviceData.

Register

MessagingNotificationFirebaseDeviceDatabase::Register(int $memberId, string $token, string $platform): int

Register a device token for a member. When the token already exists, updates the member association, platform and last-used timestamp; when it is new, inserts a new record.

NameTypeDescription
$memberIdintThe member id.
$tokenstringThe FCM device token.
$platformstringThe platform (ios, android, web).

Returns int The device id.

MessagingNotificationFirebaseDeviceData

Immutable data for one registered device token. Fields and constructor only.

Properties

PropertyTypeDescription
$data->idintThe device id (readonly).
$data->memberIdintThe member the token belongs to (readonly).
$data->tokenstringThe FCM device token (readonly).
$data->platformstringThe platform, for example ios, android or web (readonly).
$data->addedTimestampCalendarDateTimeDataWhen the token was first registered (readonly).
$data->lastUsedTimestampCalendarDateTimeDataWhen the token was last used (readonly).

__construct

new MessagingNotificationFirebaseDeviceData(int $id = 0, int $memberId = 0, string $token = '', string $platform = '', CalendarDateTimeData $addedTimestamp = new CalendarDateTimeData(), CalendarDateTimeData $lastUsedTimestamp = new CalendarDateTimeData())

Create device data from an id, member id, token, platform and the added and last-used timestamps.

NameTypeDescription
$idintThe device id.
$memberIdintThe member the token belongs to.
$tokenstringThe FCM device token.
$platformstringThe platform.
$addedTimestampCalendarDateTimeDataWhen the token was first registered.
$lastUsedTimestampCalendarDateTimeDataWhen the token was last used.

Returns MessagingNotificationFirebaseDeviceData