Skip to content

Commit c6e2360

Browse files
committed
fix merge
1 parent 6f500fb commit c6e2360

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/Notification.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct($endpoint, $payload, $userPublicKey)
2626
{
2727
$this->endpoint = $endpoint;
2828
$this->payload = $payload;
29-
$this->userPublicKey = $payload;
29+
$this->userPublicKey = $userPublicKey;
3030
}
3131

3232
/**
@@ -36,4 +36,20 @@ public function getEndpoint()
3636
{
3737
return $this->endpoint;
3838
}
39+
40+
/**
41+
* @return null|string
42+
*/
43+
public function getPayload()
44+
{
45+
return $this->payload;
46+
}
47+
48+
/**
49+
* @return null|string
50+
*/
51+
public function getUserPublicKey()
52+
{
53+
return $this->userPublicKey;
54+
}
3955
}

src/WebPush.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,16 @@ private function encrypt($userPublicKey, $payload)
187187
);
188188
}
189189

190-
/**
191-
* @param array $endpoints
192-
* @param array|null $payloads
193-
* @param array|null $userPublicKeys
194-
*
195-
* @return array
196-
*
197-
* @throws \ErrorException
198-
*/
199190
private function sendToStandardEndpoints(array $notifications)
200191
{
201192
$responses = array();
202-
foreach ($endpoints as $i => $endpoint) {
203-
$payload = $payloads[$i];
193+
/** @var Notification $notification */
194+
foreach ($notifications as $notification) {
195+
$payload = $notification->getPayload();
196+
$userPublicKey = $notification->getUserPublicKey();
204197

205-
if (isset($payload)) {
206-
$encrypted = $this->encrypt($userPublicKeys[$i], $payload);
198+
if (isset($payload) && isset($userPublicKey)) {
199+
$encrypted = $this->encrypt($userPublicKey, $payload);
207200

208201
$headers = array(
209202
'Content-Length' => strlen($encrypted['cipherText']),
@@ -226,9 +219,6 @@ private function sendToStandardEndpoints(array $notifications)
226219
$headers['TTL'] = $this->TTL;
227220
}
228221

229-
$responses = array();
230-
/** @var Notification $notification */
231-
foreach ($notifications as $notification) {
232222
$responses[] = $this->sendRequest($notification->getEndpoint(), $headers, $content);
233223
}
234224

0 commit comments

Comments
 (0)