Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow simple string alert for backwards compatibility #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 17 additions & 1 deletion src/Payload/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Alert implements \JsonSerializable
const ALERT_LOC_ARGS_KEY = 'loc-args';
const ALERT_LAUNCH_IMAGE_KEY = 'launch-image';

/**
* Backward compatibility w/ binary APNs protocol -- if used, all other properties are ignored and alert in payload is a string.
*/
private string $simpleAlert;

/**
* A short string describing the purpose of the notification.
*
Expand Down Expand Up @@ -102,6 +107,13 @@ public static function create()
return new self();
}

public function setSimpleAlert(string $text): self
{
$this->simpleAlert = $text;

return $this;
}

/**
* Set Alert title.
*
Expand Down Expand Up @@ -325,8 +337,12 @@ public function toJson(): string
* @return array
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
*/
public function jsonSerialize(): array
public function jsonSerialize(): array|string
{
if (!empty($this->simpleAlert)) {
return $this->simpleAlert;
}

$alert = [];

if (is_string($this->title)) {
Expand Down