Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/Lunr/Vortex/PushNotificationDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

/**
* Generic Push Notification Dispatcher.
*
* @phpstan-type Endpoint array<string, scalar|null>&array{
* platform: string,
* payloadType: string,
* endpoint: string
* }
*/
class PushNotificationDispatcher
{
Expand All @@ -26,7 +32,7 @@ class PushNotificationDispatcher

/**
* List of Push Notification status codes for every endpoint.
* @var array<value-of<PushNotificationStatus>, array>
* @var array<value-of<PushNotificationStatus>, Endpoint[]>
*/
protected array $statuses;

Expand Down Expand Up @@ -78,10 +84,9 @@ public function register_dispatcher(string $platform, PushNotificationDispatcher
/**
* Push the notification.
*
* @param array $endpoints Array containing lists of endpoints
* paired to their respective platform identifiers
* @param array $payloads Associative array containing payload strings
* per platform identifier
* @param Endpoint[] $endpoints List of endpoints.
* @param array<string, array<string, PushNotificationPayloadInterface>> $payloads Associative array containing payload strings
* per platform identifier
*
* @return void
*/
Expand Down Expand Up @@ -163,19 +168,19 @@ public function dispatch(array $endpoints, array $payloads): void
/**
* Push a notification payload to each endpoint one by one
*
* @param string $platform Notification platform
* @param array $endpoints Endpoints list
* @param object $payload Payload to send
* @param string $platform Notification platform
* @param Endpoint[] $endpoints Endpoints list
* @param object $payload Payload to send
*
* @return void
*/
protected function dispatch_single(string $platform, array &$endpoints, object $payload): void
{
foreach ($endpoints as $endpoint)
{
$endpoints = [ $endpoint['endpoint'] ];
$single_endpoint = [ $endpoint['endpoint'] ];

$response = $this->dispatchers[$platform]->push($payload, $endpoints);
$response = $this->dispatchers[$platform]->push($payload, $single_endpoint);

$status = $response->get_status($endpoint['endpoint']);

Expand All @@ -186,9 +191,9 @@ protected function dispatch_single(string $platform, array &$endpoints, object $
/**
* Push a notification payload to each endpoint in a multicast way
*
* @param string $platform Notification platform
* @param array $endpoints Endpoints list
* @param object $payload Payload to send
* @param string $platform Notification platform
* @param Endpoint[] $endpoints Endpoints list
* @param object $payload Payload to send
*
* @return void
*/
Expand Down Expand Up @@ -243,7 +248,7 @@ protected function dispatch_broadcast(string $platform, string $payload_type, Pu
*
* @param value-of<PushNotificationStatus>[] $status_codes The list of status codes
*
* @return array The endpoint & platform pairs
* @return Endpoint[] The endpoint & platform pairs
*/
public function get_endpoints_by_status(array $status_codes): array
{
Expand All @@ -270,7 +275,7 @@ public function get_endpoints_by_status(array $status_codes): array
/**
* Return unfiltered status information.
*
* @return array Array of endpoint & platforms pairs structured by status.
* @return array<value-of<PushNotificationStatus>, Endpoint[]> Array of endpoint & platforms pairs structured by status.
*/
public function get_statuses(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Lunr/Vortex/PushNotificationDispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ interface PushNotificationDispatcherInterface
/**
* Push the notification.
*
* @param object $payload Payload object
* @param array $endpoints Endpoints to sent it to in this batch
* @param object $payload Payload object
* @param string[] $endpoints Endpoints to sent it to in this batch
*
* @return PushNotificationResponseInterface Response object
*/
Expand Down