Skip to content
Merged
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
36 changes: 36 additions & 0 deletions library/CodeMonkeysRu/GCM/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
class Message
{
const PRIORITY_NORMAL = 'normal';
const PRIORITY_HIGH = 'high';

/**
* A string array with the list of devices (registration IDs) receiving the message.
Expand Down Expand Up @@ -96,6 +98,21 @@ class Message
*/
private $contentAvailable = true;

/**
* Sets the priority of the message. Valid values are "normal" and "high." On iOS, these
* correspond to APNs priority 5 and 10. By default, messages are sent with normal
* priority. Normal priority optimizes the client app's battery consumption, and should
* be used unless immediate delivery is required. For messages with normal priority, the
* app may receive the message with unspecified delay.
* When a message is sent with high priority, it is sent immediately, and the app can wake
* a sleeping device and open a network connection to your server.
*
* Optional.
*
* @var string
*/
private $priority = self::PRIORITY_NORMAL;

/**
* Allows developers to test their request without actually sending a message.
*
Expand Down Expand Up @@ -222,4 +239,23 @@ public function setContentAvailable($contentAvailable)
$this->contentAvailable = $contentAvailable;
return $this;
}

public function getPriority()
{
return $this->priority;
}

public function setPriority($priority)
{
$allowedPriorities = array(self::PRIORITY_HIGH, self::PRIORITY_NORMAL);

if (!in_array($priority, $allowedPriorities, true)) {
throw new \InvalidArgumentException(
'Invalid priority "' . $priority . '", allowed are only these: ' . implode(', ', $allowedPriorities)
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add else throw Exception.
We should not mask possible dev typos.


$this->priority = $priority;
return $this;
}
}
1 change: 1 addition & 0 deletions library/CodeMonkeysRu/GCM/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private function formMessageData(Message $message)
'restricted_package_name' => 'getRestrictedPackageName',
'dry_run' => 'getDryRun',
'content_available' => 'getContentAvailable',
'priority' => 'getPriority',
);

foreach ($dataFields as $fieldName => $getter) {
Expand Down