1 | <?php |
||
25 | class ApnsAdapter extends AbstractAdapter implements PushAdapter, FeedbackAdapter |
||
26 | { |
||
27 | const RESULT_OK = 0; |
||
28 | const RESULT_UNAVAILABLE = 2048; |
||
29 | |||
30 | /** |
||
31 | * Status codes mapping. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected static $statusCodes = [ |
||
36 | 0 => 'OK', |
||
37 | 1 => 'Processing Error', |
||
38 | 2 => 'Missing Device Token', |
||
39 | 3 => 'Missing Topic', |
||
40 | 4 => 'Missing Payload', |
||
41 | 5 => 'Invalid Token Size', |
||
42 | 6 => 'Invalid Topic Size', |
||
43 | 7 => 'Invalid Payload Size', |
||
44 | 8 => 'Invalid Token', |
||
45 | 10 => 'Shutdown', |
||
46 | 255 => 'Unknown Error', |
||
47 | self::RESULT_UNAVAILABLE => 'Server Unavailable', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * APNS service builder. |
||
52 | * |
||
53 | * @var \Jgut\Tify\Adapter\Apns\ApnsBuilder |
||
54 | */ |
||
55 | protected $builder; |
||
56 | |||
57 | /** |
||
58 | * @var \ZendService\Apple\Apns\Client\Message |
||
59 | */ |
||
60 | protected $pushClient; |
||
61 | |||
62 | /** |
||
63 | * @var \ZendService\Apple\Apns\Client\Feedback |
||
64 | */ |
||
65 | protected $feedbackClient; |
||
66 | |||
67 | /** |
||
68 | * @param array $parameters |
||
69 | * @param bool $sandbox |
||
70 | * @param \Jgut\Tify\Adapter\Apns\ApnsBuilder|null $builder |
||
71 | * |
||
72 | * @throws \Jgut\Tify\Exception\AdapterException |
||
73 | */ |
||
74 | public function __construct(array $parameters = [], $sandbox = false, ApnsBuilder $builder = null) |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | * |
||
97 | * @throws \InvalidArgumentException |
||
98 | * @throws \Jgut\Tify\Exception\AdapterException |
||
99 | * @throws \ZendService\Apple\Exception\RuntimeException |
||
100 | */ |
||
101 | public function push(Notification $notification) |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | * |
||
142 | * @throws \InvalidArgumentException |
||
143 | * @throws \Jgut\Tify\Exception\AdapterException |
||
144 | * @throws \Jgut\Tify\Exception\NotificationException |
||
145 | */ |
||
146 | public function feedback() |
||
170 | |||
171 | /** |
||
172 | * Get opened ServiceClient |
||
173 | * |
||
174 | * @throws \Jgut\Tify\Exception\AdapterException |
||
175 | * |
||
176 | * @return \ZendService\Apple\Apns\Client\Message |
||
177 | */ |
||
178 | protected function getPushClient() |
||
190 | |||
191 | /** |
||
192 | * Get opened ServiceFeedbackClient |
||
193 | * |
||
194 | * @throws \Jgut\Tify\Exception\AdapterException |
||
195 | * |
||
196 | * @return \ZendService\Apple\Apns\Client\Feedback |
||
197 | */ |
||
198 | protected function getFeedbackClient() |
||
210 | |||
211 | /** |
||
212 | * Get service formatted push messages. |
||
213 | * |
||
214 | * @param \Jgut\Tify\Notification $notification |
||
215 | * |
||
216 | * @throws \ZendService\Apple\Exception\RuntimeException |
||
217 | * |
||
218 | * @return \Generator |
||
219 | */ |
||
220 | protected function getPushMessages(Notification $notification) |
||
228 | |||
229 | /** |
||
230 | * {@inheritdoc} |
||
231 | */ |
||
232 | protected function getDefinedParameters() |
||
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | */ |
||
240 | protected function getDefaultParameters() |
||
246 | |||
247 | /** |
||
248 | * {@inheritdoc} |
||
249 | */ |
||
250 | protected function getRequiredParameters() |
||
254 | } |
||
255 |