Skip to content

Commit

Permalink
Merge pull request #9 from sinemacula/feature/test-notification
Browse files Browse the repository at this point in the history
Feature/test notification
  • Loading branch information
sinemacula-ben authored Aug 12, 2024
2 parents dbbb0bf + a35f691 commit 317191d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Entities/Messages/TestNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace SineMacula\Aws\Sns\Entities\Messages;

use SineMacula\Aws\Sns\Entities\Messages\Contracts\NotificationInterface;

/**
* AWS SNS test notification instance.
*
* @author Ben Carey <[email protected]>
* @copyright 2024 Sine Macula Limited.
*/
class TestNotification extends Notification implements NotificationInterface
{ }
15 changes: 15 additions & 0 deletions src/MessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SineMacula\Aws\Sns\Entities\Messages\S3\Notification as S3Notification;
use SineMacula\Aws\Sns\Entities\Messages\Ses\Notification as SesNotification;
use SineMacula\Aws\Sns\Entities\Messages\SubscriptionConfirmation;
use SineMacula\Aws\Sns\Entities\Messages\TestNotification;
use SineMacula\Aws\Sns\Exceptions\UnsupportedMessageException;

/**
Expand All @@ -33,6 +34,7 @@ public static function make(Message $message): MessageInterface
self::isS3Notification($message) => new S3Notification($message),
self::isSesNotification($message) => new SesNotification($message),
self::isCloudWatchNotification($message) => new CloudWatchNotification($message),
self::isTestNotification($message) => new TestNotification($message),
default => throw new UnsupportedMessageException('Unsupported SNS message type: ' . $message['Type'] ?? 'Undefined')
};
}
Expand Down Expand Up @@ -92,4 +94,17 @@ private static function isCloudWatchNotification(Message $message): bool
return isset($message['AlarmName'])
&& isset($message['NewStateValue']);
}

/**
* Determine if the given message payload is a test notification.
*
* @param \Aws\Sns\Message $message
* @return bool
*/
private static function isTestNotification(Message $message): bool
{
$message = json_decode($message['Message'], true);

return str_ends_with($message['Event'] ?? '', ':TestEvent');
}
}

0 comments on commit 317191d

Please sign in to comment.