From 95afe476af1a9bbc8399ac3e9c427b174e9d0191 Mon Sep 17 00:00:00 2001 From: Ben Carey Date: Mon, 12 Aug 2024 21:15:57 +0100 Subject: [PATCH 1/2] Added test notification --- src/Entities/Messages/TestNotification.php | 13 +++++++++++++ src/MessageFactory.php | 15 +++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/Entities/Messages/TestNotification.php diff --git a/src/Entities/Messages/TestNotification.php b/src/Entities/Messages/TestNotification.php new file mode 100644 index 0000000..1adb9ff --- /dev/null +++ b/src/Entities/Messages/TestNotification.php @@ -0,0 +1,13 @@ + + * @copyright 2024 Sine Macula Limited. + */ +class TestNotification extends Notification implements NotificationInterface { } diff --git a/src/MessageFactory.php b/src/MessageFactory.php index c72ed72..840ca9d 100644 --- a/src/MessageFactory.php +++ b/src/MessageFactory.php @@ -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; /** @@ -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') }; } @@ -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'); + } } From a35f6910bef575fcff8bbe730282fb56aadcfc22 Mon Sep 17 00:00:00 2001 From: Ben Carey Date: Mon, 12 Aug 2024 20:16:12 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Entities/Messages/TestNotification.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Entities/Messages/TestNotification.php b/src/Entities/Messages/TestNotification.php index 1adb9ff..0515417 100644 --- a/src/Entities/Messages/TestNotification.php +++ b/src/Entities/Messages/TestNotification.php @@ -10,4 +10,5 @@ * @author Ben Carey * @copyright 2024 Sine Macula Limited. */ -class TestNotification extends Notification implements NotificationInterface { } +class TestNotification extends Notification implements NotificationInterface +{ }