Skip to content

Commit 913af04

Browse files
Sören UhrbachMinishlink
authored andcommitted
Fixed issue !194. (#202)
Changed the order of if-statements to solve issue 194. The problem was caused because the user provided an content encoding type. Every time if an content encoding type was given then the create method of 'Subscription' returned a new subscription based on the 'authToken' authorization format. The issue creator used the variant where you provide the array 'keys' for authorization. This format could not be used if you provided an content encoding type. This bug is now fixed by changing the if-statement order.
1 parent e29d657 commit 913af04

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Subscription.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ public function __construct(
6464
* @throws \ErrorException
6565
*/
6666
public static function create(array $associativeArray): Subscription {
67-
if (array_key_exists('publicKey', $associativeArray) || array_key_exists('authToken', $associativeArray) || array_key_exists('contentEncoding', $associativeArray)) {
67+
if (array_key_exists('keys', $associativeArray) && is_array($associativeArray['keys'])) {
6868
return new self(
6969
$associativeArray['endpoint'],
70-
$associativeArray['publicKey'] ?? null,
71-
$associativeArray['authToken'] ?? null,
70+
$associativeArray['keys']['p256dh'] ?? null,
71+
$associativeArray['keys']['auth'] ?? null,
7272
$associativeArray['contentEncoding'] ?? "aesgcm"
7373
);
7474
}
7575

76-
if (array_key_exists('keys', $associativeArray) && is_array($associativeArray['keys'])) {
76+
if (array_key_exists('publicKey', $associativeArray) || array_key_exists('authToken', $associativeArray) || array_key_exists('contentEncoding', $associativeArray)) {
7777
return new self(
7878
$associativeArray['endpoint'],
79-
$associativeArray['keys']['p256dh'] ?? null,
80-
$associativeArray['keys']['auth'] ?? null,
79+
$associativeArray['publicKey'] ?? null,
80+
$associativeArray['authToken'] ?? null,
8181
$associativeArray['contentEncoding'] ?? "aesgcm"
8282
);
8383
}

0 commit comments

Comments
 (0)