Skip to content

Instantly share code, notes, and snippets.

@poisa
Created February 28, 2013 01:01
Show Gist options
  • Save poisa/5053319 to your computer and use it in GitHub Desktop.
Save poisa/5053319 to your computer and use it in GitHub Desktop.
require 'vendor/autoload.php';
use Aws\Sns\Validator\SnsValidator;
$incomingMessage = json_decode($HTTP_RAW_POST_DATA);
try {
// Case 1:
// Full auto pilot mode (this detects the strategy based on the 'Type' property of the incoming message
$validator = new SnsValidator($incomingMessage);
// Case 2:
// Injecting the strategy by hand
$strategy = new Validator\Strategy\NotificationStrategy();
$validator = new SnsValidator($incomingMessage, $strategy);
// Case 3a:
// Specifying the strategy via a constructor string
$validator = new SnsValidator($incomingMessage, 'Notification');
// Case 3b:
// Specifying the strategy via a constructor string straight from the incoming data
$validator = new SnsValidator($incomingMessage, $incomingMessage->Type);
if ($validator->validate()) {
echo "Signature is valid\n";
} else {
echo "Signature is invalid";
}
} catch (Exception $e) {
echo $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment