You are here

class FirebaseTopicManagerService in Firebase Push Notification (FCM) 8

Same name and namespace in other branches
  1. 3.0.x src/Service/FirebaseTopicManagerService.php \Drupal\firebase\Service\FirebaseTopicManagerService

Service for managing topics.

Hierarchy

Expanded class hierarchy of FirebaseTopicManagerService

1 string reference to 'FirebaseTopicManagerService'
firebase.services.yml in ./firebase.services.yml
firebase.services.yml
1 service uses FirebaseTopicManagerService
firebase.topic_manager in ./firebase.services.yml
Drupal\firebase\Service\FirebaseTopicManagerService

File

src/Service/FirebaseTopicManagerService.php, line 12

Namespace

Drupal\firebase\Service
View source
class FirebaseTopicManagerService extends FirebaseServiceBase {

  /**
   * Endpoint for subscribe device on topic.
   */
  const SUBSCRIBE_ENDPOINT = 'https://iid.googleapis.com/iid/v1:batchAdd';

  /**
   * Endpoint for subscribe device on topic.
   */
  const UNSUBSCRIBE_ENDPOINT = 'https://iid.googleapis.com/iid/v1:batchRemove';

  /**
   * {@inheritdoc}
   */
  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');
  }

  /**
   * Process topic un/subscription.
   *
   * @param string $topic
   *   The topic, which will be processed.
   * @param string|array $tokens
   *   Token or tokens this will be subscriber\unsubscribe by topic.
   * @param string $endpoint
   *   The endpoint for processing by topic.
   */
  public function processTopicSubscription($topic, $tokens, $endpoint) {
    $this->endpoint = $endpoint;
    $this->body = [
      'to' => '/topics/' . $topic,
      'registration_tokens' => is_array($tokens) ? $tokens : [
        $tokens,
      ],
    ];
    $this
      ->send();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: sleep 1
DependencySerializationTrait::__wakeup public function Aliased as: wakeup 2
FirebaseServiceBase::$body protected property Request body.
FirebaseServiceBase::$client protected property HTTP client.
FirebaseServiceBase::$configFactory protected property The config factory.
FirebaseServiceBase::$endpoint protected property Firebase service endpoint.
FirebaseServiceBase::$key protected property Firebase API Key.
FirebaseServiceBase::$logger protected property The logger channel.
FirebaseServiceBase::buildHeader public function Build the header. Overrides FirebaseServiceInterface::buildHeader 1
FirebaseServiceBase::resetService public function Reset body of service.
FirebaseServiceBase::send public function Overrides FirebaseServiceInterface::send 1
FirebaseServiceBase::__sleep public function
FirebaseServiceBase::__wakeup public function
FirebaseTopicManagerService::processTopicSubscription public function Process topic un/subscription.
FirebaseTopicManagerService::SUBSCRIBE_ENDPOINT constant Endpoint for subscribe device on topic.
FirebaseTopicManagerService::UNSUBSCRIBE_ENDPOINT constant Endpoint for subscribe device on topic.
FirebaseTopicManagerService::__construct public function Constructs a FirebaseServiceBase object. Overrides FirebaseServiceBase::__construct