Skip to content
Open
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
31 changes: 30 additions & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Message implements \JsonSerializable
private $recipients = [];
private $recipientType;
private $jsonData;
private $badge;


public function __construct() {
Expand Down Expand Up @@ -134,6 +135,20 @@ public function setTimeToLive($value)
return $this;
}

/**
* @return mixed
*/
public function getBadge() {
return $this->badge;
}

/**
* @param mixed $badge
*/
public function setBadge($badge) {
$this->badge = $badge;
}

public function jsonSerialize()
{
$jsonData = $this->jsonData;
Expand All @@ -142,7 +157,12 @@ public function jsonSerialize()
throw new \UnexpectedValueException('Message must have at least one recipient');
}

$jsonData['to'] = $this->createTo();
$recipients = $this->createTo();
if(is_array($recipients)){
$jsonData['registration_ids'] = $recipients;
}else{
$jsonData['to'] = $recipients;
}
if ($this->collapseKey) {
$jsonData['collapse_key'] = $this->collapseKey;
}
Expand All @@ -155,6 +175,9 @@ public function jsonSerialize()
if ($this->notification) {
$jsonData['notification'] = $this->notification;
}
if ($this->badge) {
$jsonData['badge'] = $this->badge;
}

return $jsonData;
}
Expand All @@ -174,6 +197,12 @@ private function createTo()
case Device::class:
if (count($this->recipients) == 1) {
return current($this->recipients)->getToken();
}else{
$tokenArray = array();
foreach($this->recipients as $recipient){
array_push($tokenArray, $recipient->getToken());
}
return $tokenArray;
}

break;
Expand Down