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

Add message title for Google Cloud Messge (GCM) #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/Services/AbstractPushService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ abstract class AbstractPushService implements PushService
*/
protected $messageText = null;

/**
* @var string|null
* The text of the message
*/
protected $messageTitle = null;

/**
* @var array|null
* The data of the message
Expand Down
5 changes: 5 additions & 0 deletions src/Services/ApplePushService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class ApplePushService extends AbstractPushService
*/
private $client;

public function setMessageTitle($title)
{
throw new RuntimeException('APNS does not support message title');
}

/**
* @inheritdoc
*/
Expand Down
17 changes: 16 additions & 1 deletion src/Services/GooglePushService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function loadConfiguration($config)
return true;
}

/**
* Set message title
*
* @param string $title message title
*/
public function setMessageTitle($title)
{
$this->messageTitle = $title;
return $this;
}

/**
* @inheritdoc
*/
Expand All @@ -48,8 +59,12 @@ public function send()
$body['data'] = $this->messageData;
}

if ($this->messageTitle !== null) {
$body['data']['title'] = $this->messageTitle;
}

if ($this->messageText !== null) {
$body['data']['message'] = $this->messageText;
$body['data']['content'] = $this->messageText;
}

$ok = [];
Expand Down
10 changes: 10 additions & 0 deletions src/Services/PushService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public function loadConfiguration($config);
*/
public function setMessageText($message);

/**
* Set the message title for this push message.
*
* @param string $title
* The message title to set
* @return self
* This instance, to allow chaining
*/
public function setMessageTitle($title);

/**
* Set the message data for this push message.
* This will clear any previous message data
Expand Down