Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/test notification #9

Merged
merged 4 commits into from
Aug 12, 2024
Merged
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
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');
}
}