1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Alexander Zhukov <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Zbox\UnifiedPush\Message\Type; |
11
|
|
|
|
12
|
|
|
use Zbox\UnifiedPush\Message\MessageBase; |
13
|
|
|
use Zbox\UnifiedPush\NotificationService\NotificationServices; |
14
|
|
|
use Zbox\UnifiedPush\Exception\InvalidArgumentException; |
15
|
|
|
use Zbox\UnifiedPush\Exception\BadMethodCallException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class MPNSBase |
19
|
|
|
* @package Zbox\UnifiedPush\Message\Type |
20
|
|
|
*/ |
21
|
|
|
class MPNSBase extends MessageBase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* MPNs does not support multicast sending |
25
|
|
|
*/ |
26
|
|
|
const MAX_RECIPIENTS_PER_MESSAGE_COUNT = 1; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Notification delivery interval |
30
|
|
|
* |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $delayInterval; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getMessageType() |
39
|
|
|
{ |
40
|
|
|
return NotificationServices::MICROSOFT_PUSH_NOTIFICATIONS_SERVICE; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function getMPNSType() |
47
|
|
|
{ |
48
|
|
|
return static::MESSAGE_TYPE; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* No expiration time available in MPN |
53
|
|
|
* |
54
|
|
|
* @throws BadMethodCallException |
55
|
|
|
*/ |
56
|
|
|
public function getExpirationTime() |
57
|
|
|
{ |
58
|
|
|
throw new BadMethodCallException("No expiration time available in MPN"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return int |
63
|
|
|
*/ |
64
|
|
|
public function getDelayInterval() |
65
|
|
|
{ |
66
|
|
|
if (!$this->delayInterval) { |
67
|
|
|
$this->setDelayInterval(static::DELAY_INTERVAL_IMMEDIATE); |
68
|
|
|
} |
69
|
|
|
return $this->delayInterval; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param int $delayInterval |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
|
|
public function setDelayInterval($delayInterval) |
77
|
|
|
{ |
78
|
|
|
if (!in_array($delayInterval, array( |
79
|
|
|
static::DELAY_INTERVAL_IMMEDIATE, |
80
|
|
|
static::DELAY_INTERVAL_450, |
81
|
|
|
static::DELAY_INTERVAL_900 |
82
|
|
|
))) { |
83
|
|
|
throw new InvalidArgumentException('Delivery interval must be equal one of predefined interval flag'); |
84
|
|
|
} |
85
|
|
|
$this->delayInterval = $delayInterval; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function validateRecipient($token) |
94
|
|
|
{ |
95
|
|
|
if (base64_encode(base64_decode($token)) !== $token) { |
96
|
|
|
throw new InvalidArgumentException(sprintf( |
97
|
|
|
'Device token must be base64 string. Token given: "%s"', |
98
|
|
|
$token |
99
|
|
|
)); |
100
|
|
|
} |
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return \ReflectionProperty[] |
106
|
|
|
*/ |
107
|
|
|
public function getPropertiesList() |
108
|
|
|
{ |
109
|
|
|
$reflection = new \ReflectionObject($this); |
110
|
|
|
$properties = $reflection->getProperties(\ReflectionProperty::IS_PRIVATE); |
111
|
|
|
|
112
|
|
|
return $properties; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|