class FirebaseGroupManagerService in Firebase Push Notification (FCM) 8
Same name and namespace in other branches
- 3.0.x src/Service/FirebaseGroupManagerService.php \Drupal\firebase\Service\FirebaseGroupManagerService
Service for managing device groups.
Hierarchy
- class \Drupal\firebase\Service\FirebaseServiceBase implements FirebaseServiceInterface uses DependencySerializationTrait
- class \Drupal\firebase\Service\FirebaseGroupManagerService
Expanded class hierarchy of FirebaseGroupManagerService
1 string reference to 'FirebaseGroupManagerService'
1 service uses FirebaseGroupManagerService
File
- src/
Service/ FirebaseGroupManagerService.php, line 12
Namespace
Drupal\firebase\ServiceView source
class FirebaseGroupManagerService extends FirebaseServiceBase {
/**
* Maximum devices in group.
*/
const MAX_DEVICES = 20;
/**
* Endpoint for send message.
*/
const ENDPOINT = 'https://fcm.googleapis.com/fcm/notification';
/**
* {@inheritdoc}
*/
public function __construct(ConfigFactory $configFactory, Client $client, LoggerChannelInterface $loggerChannel) {
parent::__construct($configFactory, $client, $loggerChannel);
$config = $this->configFactory
->get('firebase.settings');
$this->key = $config
->get('server_key');
$this->endpoint = self::ENDPOINT;
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
return parent::buildHeader() + [
'project_id' => $this->configFactory
->get('firebase.settings')
->get('sender_id'),
];
}
/**
* Method for creation new device group.
*
* @param string $groupName
* Unique name for the group of devices.
* @param array $deviceTokens
* Device or devices tokens, which should be combined into one group.
*
* @return bool|array
* Result from FCM.
*/
public function createGroup($groupName, array $deviceTokens = []) {
if (!$groupName || empty($deviceTokens)) {
return FALSE;
}
if (count($deviceTokens) > self::MAX_DEVICES) {
throw new \OutOfRangeException('Device in group limit exceeded. Firebase supports a maximum of %u devices in one group.', self::MAX_DEVICES);
}
$this->body = [
'operation' => 'create',
'notification_key_name' => $groupName,
'registration_ids' => $deviceTokens,
];
return $this
->send();
}
/**
* Method for adding new devices to an existing group.
*
* @param string $groupName
* Unique name for the group of devices.
* @param string $groupToken
* The token for identify group in FCM.
* @param array $deviceTokens
* Device or devices tokens, which should be combined into one group.
*
* @return bool|array
* Result from FCM.
*/
public function addToGroup($groupName, $groupToken, array $deviceTokens) {
if (!$groupName || empty($deviceTokens) || !$groupToken) {
return FALSE;
}
if (count($deviceTokens) > self::MAX_DEVICES) {
throw new \OutOfRangeException('Device in group limit exceeded. Firebase supports a maximum of %u devices in one group.', self::MAX_DEVICES);
}
$this->body = [
'operation' => 'add',
'notification_key_name' => $groupName,
'notification_key' => $groupToken,
'registration_ids' => $deviceTokens,
];
return $this
->send();
}
/**
* Method for removing devices from existing group.
*
* @param string $groupName
* Unique name for the group of devices.
* @param string $groupToken
* The token for identify group in FCM.
* @param array $deviceTokens
* Device or devices tokens, which should be combined into one group.
*
* @return bool|array
* Result from FCM.
*/
public function removeFromGroup($groupName, $groupToken, array $deviceTokens) {
if (!$groupName || empty($deviceTokens) || !$groupToken) {
return FALSE;
}
$this->body = [
'operation' => 'remove',
'notification_key_name' => $groupName,
'notification_key' => $groupToken,
'registration_ids' => $deviceTokens,
];
return $this
->send();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | Aliased as: sleep | 1 |
DependencySerializationTrait:: |
public | function | Aliased as: wakeup | 2 |
FirebaseGroupManagerService:: |
public | function | Method for adding new devices to an existing group. | |
FirebaseGroupManagerService:: |
public | function |
Build the header. Overrides FirebaseServiceBase:: |
|
FirebaseGroupManagerService:: |
public | function | Method for creation new device group. | |
FirebaseGroupManagerService:: |
constant | Endpoint for send message. | ||
FirebaseGroupManagerService:: |
constant | Maximum devices in group. | ||
FirebaseGroupManagerService:: |
public | function | Method for removing devices from existing group. | |
FirebaseGroupManagerService:: |
public | function |
Constructs a FirebaseServiceBase object. Overrides FirebaseServiceBase:: |
|
FirebaseServiceBase:: |
protected | property | Request body. | |
FirebaseServiceBase:: |
protected | property | HTTP client. | |
FirebaseServiceBase:: |
protected | property | The config factory. | |
FirebaseServiceBase:: |
protected | property | Firebase service endpoint. | |
FirebaseServiceBase:: |
protected | property | Firebase API Key. | |
FirebaseServiceBase:: |
protected | property | The logger channel. | |
FirebaseServiceBase:: |
public | function | Reset body of service. | |
FirebaseServiceBase:: |
public | function |
Overrides FirebaseServiceInterface:: |
1 |
FirebaseServiceBase:: |
public | function | ||
FirebaseServiceBase:: |
public | function |