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.
MessagingNotificationProviderFirebase- send a push notification through Firebase Cloud Messaging.MessagingNotificationFirebaseDeviceDatabase- store and read the Firebase device tokens registered for members.MessagingNotificationFirebaseDeviceData- immutable data for one registered device token.
MessagingNotificationProviderFirebase
Send a push notification to a single device through the Firebase Cloud Messaging HTTP API, using the server key from the module configuration.
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.
| Name | Type | Description |
|---|---|---|
$deviceToken | string | Device FCM token. |
$title | string | Notification title. |
$body | string | Notification body text. |
$optionalData | ?array | Optional 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.
| Name | Type | Description |
|---|---|---|
$token | string | The FCM device token to delete. |
Returns void
GetById
MessagingNotificationFirebaseDeviceDatabase::GetById(int $id): MessagingNotificationFirebaseDeviceData
Get device by id.
| Name | Type | Description |
|---|---|---|
$id | int | The device id. |
Returns MessagingNotificationFirebaseDeviceData The device.
GetTokensForMember
MessagingNotificationFirebaseDeviceDatabase::GetTokensForMember(int $memberId): array
Get all device tokens for a member, most recently used first.
| Name | Type | Description |
|---|---|---|
$memberId | int | The 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.
| Name | Type | Description |
|---|---|---|
$memberId | int | The member id. |
$token | string | The FCM device token. |
$platform | string | The platform (ios, android, web). |
Returns int The device id.
MessagingNotificationFirebaseDeviceData
Immutable data for one registered device token. Fields and constructor only.
Properties
| Property | Type | Description |
|---|---|---|
$data->id | int | The device id (readonly). |
$data->memberId | int | The member the token belongs to (readonly). |
$data->token | string | The FCM device token (readonly). |
$data->platform | string | The platform, for example ios, android or web (readonly). |
$data->addedTimestamp | CalendarDateTimeData | When the token was first registered (readonly). |
$data->lastUsedTimestamp | CalendarDateTimeData | When 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.
| Name | Type | Description |
|---|---|---|
$id | int | The device id. |
$memberId | int | The member the token belongs to. |
$token | string | The FCM device token. |
$platform | string | The platform. |
$addedTimestamp | CalendarDateTimeData | When the token was first registered. |
$lastUsedTimestamp | CalendarDateTimeData | When the token was last used. |
Returns MessagingNotificationFirebaseDeviceData