Messaging
in package
Class for sending messages.
Table of Contents
Properties
- $accessTokenHandler : AccessTokenHandler
- $cache : CacheInterface
- $logger : LoggerInterface|null
Methods
- __construct() : mixed
- getAccessTokenHandler() : AccessTokenHandler
- Returns the AccessTokenHandler instance.
- getInfo() : array<string|int, mixed>
- Gets info about a specific token.
- sendAll() : SendAllResult
- Send multiple messages.
- sendToTopic() : bool
- Sends a message to a topic
- subscribeToTopic() : bool
- Subscribe token to topic.
- unsubscribeFromTopic() : bool
- Unsubscribe tokens from topic.
- validateAll() : SendAllResult
- Validate multiple messages. Can be used to check if tokens are still registered.
- _sendAll() : SendAllResult
- Send multiple messages with an optional retry in case of expired access token.
- callWithRetryOnExpiredAccessToken() : ResponseInterface
- Call the Google API with one retry in case of expired access token.
Properties
$accessTokenHandler
private
AccessTokenHandler
$accessTokenHandler
$cache
private
CacheInterface
$cache
$logger read-only
private
LoggerInterface|null
$logger
Methods
__construct()
public
__construct(CacheInterface $cache, string $jsonFile, LoggerInterface|null $logger) : mixed
Parameters
- $cache : CacheInterface
-
A CacheInterface implemenation. This will be used to cache the access token.
- $jsonFile : string
-
The path to the Google Firebase private key file in JSON format.
- $logger : LoggerInterface|null
-
An optional LoggerInterface implemenation.
getAccessTokenHandler()
Returns the AccessTokenHandler instance.
public
getAccessTokenHandler() : AccessTokenHandler
Return values
AccessTokenHandlergetInfo()
Gets info about a specific token.
public
getInfo(string $token[, string $details = false ]) : array<string|int, mixed>
Parameters
- $token : string
-
The registration token.
- $details : string = false
-
If we want more details for this token, like the topics for this token.
Tags
Return values
array<string|int, mixed> —JSON response.
sendAll()
Send multiple messages.
public
sendAll(array<string|int, TokenMessage> $tokenMessages) : SendAllResult
Parameters
- $tokenMessages : array<string|int, TokenMessage>
-
A list of messages to send.
Tags
Return values
SendAllResult —A SendAllResult result, which contains the sent, unregistered and error
sendToTopic()
Sends a message to a topic
public
sendToTopic(TopicMessage $topicMessage) : bool
Parameters
- $topicMessage : TopicMessage
-
The message to send.
Tags
Return values
bool —True if we got a 200 status code.
subscribeToTopic()
Subscribe token to topic.
public
subscribeToTopic(string $token, string $topic) : bool
Parameters
- $token : string
-
The registration token.
- $topic : string
-
The topic.
Tags
Return values
bool —True if we got a 200 status code.
unsubscribeFromTopic()
Unsubscribe tokens from topic.
public
unsubscribeFromTopic(array<string|int, mixed> $tokens, string $topic) : bool
Parameters
- $tokens : array<string|int, mixed>
-
Array with tokens.
- $topic : string
-
Topic name.
Tags
Return values
bool —True if we got a 200 status code.
validateAll()
Validate multiple messages. Can be used to check if tokens are still registered.
public
validateAll(array<string|int, TokenMessage> $tokenMessages) : SendAllResult
Parameters
- $tokenMessages : array<string|int, TokenMessage>
-
A list of messages to validate.
Tags
Return values
SendAllResult —A SendAllResult result, which contains the sent, unregistered and error
_sendAll()
Send multiple messages with an optional retry in case of expired access token.
private
_sendAll(array<string|int, TokenMessage> $tokenMessages[, bool $validate = false ][, SendAllResult|null $sendAllResult = null ]) : SendAllResult
Parameters
- $tokenMessages : array<string|int, TokenMessage>
-
A list of messages to send.
- $validate : bool = false
- $sendAllResult : SendAllResult|null = null
-
The SendAllResult instance (this is only defined if this is a retry in case of expired access token).
Tags
Return values
SendAllResult —A SendAllResult result, which contains the sent, unregistered and error
callWithRetryOnExpiredAccessToken()
Call the Google API with one retry in case of expired access token.
private
callWithRetryOnExpiredAccessToken(string $uri[, string $method = 'POST' ][, array<string|int, mixed>|null $json = null ][, array<string|int, mixed>|null $headers = null ][, bool $retry = false ]) : ResponseInterface
Parameters
- $uri : string
-
Google API endpoint.
- $method : string = 'POST'
-
Method for API request.
- $json : array<string|int, mixed>|null = null
-
The JSON body.
- $headers : array<string|int, mixed>|null = null
-
The headers.
- $retry : bool = false
-
If this is the retry phase.
Tags
Return values
ResponseInterface —The ResponseInterface instance.