Skip to content

Commit 87706c3

Browse files
committed
Make *URL or *Url a valid key suffix when constructing a Message
1 parent 492d039 commit 87706c3

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/Message.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ class Message implements \ArrayAccess, \IteratorAggregate
1515
'TopicArn',
1616
'Type',
1717
'Signature',
18-
'SigningCertURL',
18+
['SigningCertURL', 'SigningCertUrl'],
1919
'SignatureVersion',
2020
];
2121

22+
private static $subscribeKeys = [
23+
['SubscribeURL', 'SubscribeUrl'],
24+
'Token'
25+
];
26+
2227
/** @var array The message data */
2328
private $data;
2429

@@ -81,7 +86,7 @@ public function __construct(array $data)
8186
if ($data['Type'] === 'SubscriptionConfirmation'
8287
|| $data['Type'] === 'UnsubscribeConfirmation'
8388
) {
84-
$this->validateRequiredKeys($data, ['SubscribeURL', 'Token']);
89+
$this->validateRequiredKeys($data, self::$subscribeKeys);
8590
}
8691

8792
$this->data = $data;
@@ -125,7 +130,23 @@ public function toArray()
125130
private function validateRequiredKeys(array $data, array $keys)
126131
{
127132
foreach ($keys as $key) {
128-
if (!isset($data[$key])) {
133+
$keyIsArray = is_array($key);
134+
if (!$keyIsArray) {
135+
$found = isset($data[$key]);
136+
} else {
137+
$found = false;
138+
foreach ($key as $keyOption) {
139+
if (isset($data[$keyOption])) {
140+
$found = true;
141+
break;
142+
}
143+
}
144+
}
145+
146+
if (!$found) {
147+
if ($keyIsArray) {
148+
$key = $key[0];
149+
}
129150
throw new \InvalidArgumentException(
130151
"\"{$key}\" is required to verify the SNS Message."
131152
);

0 commit comments

Comments
 (0)