|
8 | 8 | */ |
9 | 9 | class Message |
10 | 10 | { |
| 11 | + const PRIORITY_NORMAL = 'normal'; |
| 12 | + const PRIORITY_HIGH = 'high'; |
11 | 13 |
|
12 | 14 | /** |
13 | 15 | * A string array with the list of devices (registration IDs) receiving the message. |
@@ -96,6 +98,21 @@ class Message |
96 | 98 | */ |
97 | 99 | private $contentAvailable = true; |
98 | 100 |
|
| 101 | + /** |
| 102 | + * Sets the priority of the message. Valid values are "normal" and "high." On iOS, these |
| 103 | + * correspond to APNs priority 5 and 10. By default, messages are sent with normal |
| 104 | + * priority. Normal priority optimizes the client app's battery consumption, and should |
| 105 | + * be used unless immediate delivery is required. For messages with normal priority, the |
| 106 | + * app may receive the message with unspecified delay. |
| 107 | + * When a message is sent with high priority, it is sent immediately, and the app can wake |
| 108 | + * a sleeping device and open a network connection to your server. |
| 109 | + * |
| 110 | + * Optional. |
| 111 | + * |
| 112 | + * @var string |
| 113 | + */ |
| 114 | + private $priority = self::PRIORITY_NORMAL; |
| 115 | + |
99 | 116 | /** |
100 | 117 | * Allows developers to test their request without actually sending a message. |
101 | 118 | * |
@@ -222,4 +239,23 @@ public function setContentAvailable($contentAvailable) |
222 | 239 | $this->contentAvailable = $contentAvailable; |
223 | 240 | return $this; |
224 | 241 | } |
| 242 | + |
| 243 | + public function getPriority() |
| 244 | + { |
| 245 | + return $this->priority; |
| 246 | + } |
| 247 | + |
| 248 | + public function setPriority($priority) |
| 249 | + { |
| 250 | + $allowedPriorities = array(self::PRIORITY_HIGH, self::PRIORITY_NORMAL); |
| 251 | + |
| 252 | + if (!in_array($priority, $allowedPriorities, true)) { |
| 253 | + throw new \InvalidArgumentException( |
| 254 | + 'Invalid priority "' . $priority . '", allowed are only these: ' . implode(', ', $allowedPriorities) |
| 255 | + ); |
| 256 | + } |
| 257 | + |
| 258 | + $this->priority = $priority; |
| 259 | + return $this; |
| 260 | + } |
225 | 261 | } |
0 commit comments