Documentation

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

$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.

getInfo()

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
throws
FcmException

If we get a Google error.

throws
Exception

For all other errors.

link
https://developers.google.com/instance-id/reference/server#get_information_about_app_instances
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
throws
FcmClientException

In case we cannot generate a JWT token.

throws
FcmException

If we get a Google error.

throws
Exception

For all other errors.

link
https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices
Return values
SendAllResult

A SendAllResult result, which contains the sent, unregistered and error

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
throws
FcmException

If we get a Google error.

throws
Exception

For all other errors.

link
https://developers.google.com/instance-id/reference/server#manage_relationship_maps_for_multiple_app_instances
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
throws
FcmClientException

In case we cannot generate a JWT token.

throws
FcmException

If we get a Google error.

throws
Exception

For all other errors.

link
https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices
link
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
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
throws
FcmClientException

In case we cannot generate a JWT token.

throws
FcmException

If we get a Google error.

throws
Exception

For all other errors.

link
https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices
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
throws
FcmClientException

In case we cannot generate a JWT token. This is always fatal and we cannot fix this without making changes to the code or to the downloaded service account private key.

throws
FcmException

In case of a Google API error, like an invalid request for the access token.

throws
Exception

In case of some other error.

Return values
ResponseInterface

The ResponseInterface instance.


        
On this page

Search results