You are here

private function FirebaseMessageService::checkReservedKeywords in Firebase Push Notification (FCM) 8

Same name and namespace in other branches
  1. 3.0.x src/Service/FirebaseMessageService.php \Drupal\firebase\Service\FirebaseMessageService::checkReservedKeywords()

Validate reserved keywords on data.

The key should not be a reserved word ("from" or any word starting with "google" or "gcm"). Do not use any of the words defined here https://firebase.google.com/docs/cloud-messaging/http-server-ref.

Not checking ALL reserved keywords. Just eliminating the common ones. Created this function to document this important restriction.

Parameters

array $data: Params that builds Push message payload.

Return value

bool TRUE if keys are fine, and FALSE if not.

1 call to FirebaseMessageService::checkReservedKeywords()
FirebaseMessageService::setData in src/Service/FirebaseMessageService.php
Add data to message.

File

src/Service/FirebaseMessageService.php, line 82

Class

FirebaseMessageService
Service for pushing message to mobile devices using Firebase.

Namespace

Drupal\firebase\Service

Code

private function checkReservedKeywords(array $data) {
  foreach ($data as $key => $value) {
    if (preg_match('/(^from$)|(^gcm)|(^google)/', $key)) {
      return FALSE;
    }
  }
  return TRUE;
}