1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the AppleApnPush package |
5
|
|
|
* |
6
|
|
|
* (c) Vitaliy Zhuk <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Apple\ApnPush\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Push message |
16
|
|
|
*/ |
17
|
|
|
class Message |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var ApnId |
21
|
|
|
*/ |
22
|
|
|
private $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ApsData |
26
|
|
|
*/ |
27
|
|
|
private $aps; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Priority |
31
|
|
|
*/ |
32
|
|
|
private $priority; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \DateTime |
36
|
|
|
*/ |
37
|
|
|
private $expiration; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private $customData; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Constructor. |
46
|
|
|
* |
47
|
|
|
* @param ApsData $apsData |
48
|
|
|
* @param ApnId|null $id |
49
|
|
|
* @param Priority|null $priority |
50
|
|
|
* @param Expiration|null $expiration |
51
|
|
|
* @param array $customData |
52
|
|
|
*/ |
53
|
|
|
public function __construct( |
54
|
|
|
ApsData $apsData, |
55
|
|
|
ApnId $id = null, |
56
|
|
|
Priority $priority = null, |
57
|
|
|
Expiration $expiration = null, |
58
|
|
|
array $customData = [] |
59
|
|
|
) { |
60
|
|
|
$this->aps = $apsData; |
61
|
|
|
$this->priority = $priority ?: Priority::fromNull(); |
62
|
|
|
$this->id = $id ?: ApnId::fromNull(); |
63
|
|
|
$this->expiration = $expiration ?: Expiration::fromNull(); |
|
|
|
|
64
|
|
|
$this->customData = $customData; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get identifier of message |
69
|
|
|
* |
70
|
|
|
* @return ApnId |
71
|
|
|
*/ |
72
|
|
|
public function getId() : ApnId |
73
|
|
|
{ |
74
|
|
|
return $this->id; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get APS data |
79
|
|
|
* |
80
|
|
|
* @return ApsData |
81
|
|
|
*/ |
82
|
|
|
public function getApsData() : ApsData |
83
|
|
|
{ |
84
|
|
|
return $this->aps; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get priority |
89
|
|
|
* |
90
|
|
|
* @return Priority |
91
|
|
|
*/ |
92
|
|
|
public function getPriority() : Priority |
93
|
|
|
{ |
94
|
|
|
return $this->priority; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get expiration |
99
|
|
|
* |
100
|
|
|
* @return Expiration |
101
|
|
|
*/ |
102
|
|
|
public function getExpiration() : Expiration |
103
|
|
|
{ |
104
|
|
|
return $this->expiration; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Add or replace custom data |
109
|
|
|
* |
110
|
|
|
* @param string $name |
111
|
|
|
* @param mixed $value |
112
|
|
|
* |
113
|
|
|
* @return Message |
114
|
|
|
* |
115
|
|
|
* @throws \InvalidArgumentException |
116
|
|
|
*/ |
117
|
|
|
public function withCustomData(string $name, $value) |
118
|
|
|
{ |
119
|
|
|
if ($value && !is_array($value) && !is_scalar($value) && !$value instanceof \JsonSerializable) { |
|
|
|
|
120
|
|
|
throw new \InvalidArgumentException(sprintf( |
121
|
|
|
'The custom data value should be a scalar or \JsonSerializable instance, but "%s" given.', |
122
|
|
|
is_object($value) ? get_class($value) : gettype($value) |
123
|
|
|
)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$cloned = clone $this; |
127
|
|
|
|
128
|
|
|
$cloned->customData[$name] = $value; |
129
|
|
|
|
130
|
|
|
return $cloned; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get custom data |
135
|
|
|
* |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
|
|
public function getCustomData() |
139
|
|
|
{ |
140
|
|
|
return $this->customData; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..