You are here

public function FirebaseMessageService::send 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::send()

Throws

\Exception

Overrides FirebaseServiceBase::send

File

src/Service/FirebaseMessageService.php, line 205

Class

FirebaseMessageService
Service for pushing message to mobile devices using Firebase.

Namespace

Drupal\firebase\Service

Code

public function send() {

  // Message should contain notification or data array, thereby referring to
  // one of the types of messages.
  // @see https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
  if (!isset($this->body['notification']) && !isset($this->body['data'])) {
    throw new \InvalidArgumentException('The message must belong to one of the message types (notification or data message).');
  }

  // We shouldn't send message without target.
  // @see https://firebase.google.com/docs/cloud-messaging/http-server-ref
  if (!isset($this->body['to']) && !isset($this->body['registration_ids']) && !isset($this->body['condition'])) {
    throw new \InvalidArgumentException('The message should contain target.');
  }
  return parent::send();
}