FirebaseTopicManagerService.php in Firebase Push Notification (FCM) 8
File
src/Service/FirebaseTopicManagerService.php
View source
<?php
namespace Drupal\firebase\Service;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Logger\LoggerChannelInterface;
use GuzzleHttp\ClientInterface;
class FirebaseTopicManagerService extends FirebaseServiceBase {
const SUBSCRIBE_ENDPOINT = 'https://iid.googleapis.com/iid/v1:batchAdd';
const UNSUBSCRIBE_ENDPOINT = 'https://iid.googleapis.com/iid/v1:batchRemove';
public function __construct(ConfigFactory $configFactory, ClientInterface $client, LoggerChannelInterface $loggerChannel) {
parent::__construct($configFactory, $client, $loggerChannel);
$config = $this->configFactory
->get('firebase.settings');
$this->key = $config
->get('server_key');
}
public function processTopicSubscription($topic, $tokens, $endpoint) {
$this->endpoint = $endpoint;
$this->body = [
'to' => '/topics/' . $topic,
'registration_tokens' => is_array($tokens) ? $tokens : [
$tokens,
],
];
$this
->send();
}
}