1 | <?php |
||
20 | abstract class MessageBase implements MessageInterface |
||
21 | { |
||
22 | /** |
||
23 | * Default modifier (a date/time string) |
||
24 | */ |
||
25 | const DEFAULT_EXPIRATION_TIME_MODIFIER = '4 weeks'; |
||
26 | |||
27 | /** |
||
28 | * A UNIX epoch date expressed in seconds (UTC) that identifies |
||
29 | * when the notification is no longer valid and can be discarded |
||
30 | * |
||
31 | * @var \DateTime |
||
32 | */ |
||
33 | protected $expirationTime; |
||
34 | |||
35 | /** |
||
36 | * An arbitrary, opaque value that identifies this notification. |
||
37 | * This identifier is used for reporting errors to your server |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $messageIdentifier; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Collection of recipient devices |
||
46 | * |
||
47 | * @var \ArrayIterator |
||
48 | */ |
||
49 | protected $recipientCollection; |
||
50 | |||
51 | /** |
||
52 | * @param array $data |
||
53 | */ |
||
54 | public function __construct(array $data = array()) |
||
69 | |||
70 | /** |
||
71 | * Checks if recipient`s token is valid |
||
72 | * |
||
73 | * @param string $token |
||
74 | * @return bool |
||
75 | * @throws InvalidArgumentException |
||
76 | */ |
||
77 | abstract public function validateRecipient($token); |
||
78 | |||
79 | /** |
||
80 | * Gets number of recipients allowed for single notification |
||
81 | * |
||
82 | * @return int |
||
83 | */ |
||
84 | public function getMaxRecipientsPerMessage() |
||
88 | |||
89 | /** |
||
90 | * Gets maximum size allowed for notification payload |
||
91 | * |
||
92 | * @return int |
||
93 | */ |
||
94 | public function getPayloadMaxLength() |
||
98 | |||
99 | /** |
||
100 | * @return RecipientDevice |
||
101 | */ |
||
102 | public function getRecipientDevice() |
||
103 | { |
||
104 | $collection = $this->recipientCollection; |
||
105 | |||
106 | if ($collection->valid()) { |
||
107 | $device = $collection->current(); |
||
108 | $collection->next(); |
||
109 | return $device; |
||
110 | } |
||
111 | return null; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return \ArrayIterator |
||
116 | */ |
||
117 | public function getRecipientCollection() |
||
121 | |||
122 | /** |
||
123 | * @param \ArrayIterator $collection |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function setRecipientCollection(\ArrayIterator $collection) |
||
131 | |||
132 | /** |
||
133 | * @param \ArrayIterator $collection |
||
134 | * @return $this |
||
135 | */ |
||
136 | public function addRecipientIdentifiers(\ArrayIterator $collection) |
||
146 | |||
147 | /** |
||
148 | * @param string $deviceIdentifier |
||
149 | * @return $this |
||
150 | */ |
||
151 | public function addRecipient($deviceIdentifier) |
||
158 | |||
159 | /** |
||
160 | * @return \DateTime |
||
161 | */ |
||
162 | public function getExpirationTime() |
||
169 | |||
170 | /** |
||
171 | * @param \DateTime $expirationTime |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function setExpirationTime(\DateTime $expirationTime) |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getMessageIdentifier() |
||
187 | |||
188 | /** |
||
189 | * @param string $messageIdentifier |
||
190 | * @throws InvalidArgumentException |
||
191 | */ |
||
192 | public function setMessageIdentifier($messageIdentifier) |
||
199 | |||
200 | /** |
||
201 | * Bad method call exception |
||
202 | * |
||
203 | * @param string $name |
||
204 | * @throws BadMethodCallException |
||
205 | */ |
||
206 | protected function badMethodCallException($name) |
||
212 | |||
213 | /** |
||
214 | * Invalid argument exception |
||
215 | * |
||
216 | * @param string $parameterName |
||
217 | * @param string $expectedType |
||
218 | */ |
||
219 | protected function invalidArgumentException($parameterName, $expectedType) |
||
230 | |||
231 | /** |
||
232 | * Error handler for unknown property notification |
||
233 | * |
||
234 | * @param string $name |
||
235 | */ |
||
236 | public function __get($name) |
||
240 | |||
241 | /** |
||
242 | * Error handler for unknown property of notification |
||
243 | * |
||
244 | * @param string $name |
||
245 | * @param mixed $value |
||
246 | */ |
||
247 | public function __set($name, $value) |
||
251 | } |
||
252 |