1 | <?php |
||
25 | class ApnsAdapter extends AbstractAdapter implements PushAdapter, FeedbackAdapter |
||
26 | { |
||
27 | const PARAMETER_CERTIFICATE = 'certificate'; |
||
28 | const PARAMETER_PASS_PHRASE = 'pass_phrase'; |
||
29 | |||
30 | const RESPONSE_OK = 0; |
||
31 | const RESPONSE_PROCESSING_ERROR = 1; |
||
32 | const RESPONSE_MISSING_DEVICE_TOKEN = 2; |
||
33 | const RESPONSE_MISSING_TOPIC = 3; |
||
34 | const RESPONSE_MISSING_PAYLOAD = 4; |
||
35 | const RESPONSE_INVALID_TOKEN_SIZE = 5; |
||
36 | const RESPONSE_INVALID_TOPIC_SIZE = 6; |
||
37 | const RESPONSE_INVALID_PAYLOAD_SIZE = 7; |
||
38 | const RESPONSE_INVALID_TOKEN = 8; |
||
39 | const RESPONSE_UNKNOWN_ERROR = 255; |
||
40 | const RESPONSE_UNAVAILABLE = 2048; |
||
41 | |||
42 | /** |
||
43 | * Status codes mapping. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected static $statusCodeMap = [ |
||
48 | self::RESPONSE_OK => Result::STATUS_SUCCESS, |
||
49 | |||
50 | self::RESPONSE_MISSING_DEVICE_TOKEN => Result::STATUS_INVALID_MESSAGE, |
||
51 | self::RESPONSE_MISSING_TOPIC => Result::STATUS_INVALID_MESSAGE, |
||
52 | self::RESPONSE_MISSING_PAYLOAD => Result::STATUS_INVALID_MESSAGE, |
||
53 | self::RESPONSE_INVALID_TOKEN_SIZE => Result::STATUS_INVALID_MESSAGE, |
||
54 | self::RESPONSE_INVALID_TOPIC_SIZE => Result::STATUS_INVALID_MESSAGE, |
||
55 | self::RESPONSE_INVALID_PAYLOAD_SIZE => Result::STATUS_INVALID_MESSAGE, |
||
56 | |||
57 | self::RESPONSE_INVALID_TOKEN => Result::STATUS_INVALID_DEVICE, |
||
58 | |||
59 | self::RESPONSE_PROCESSING_ERROR => Result::STATUS_SERVER_ERROR, |
||
60 | self::RESPONSE_UNAVAILABLE => Result::STATUS_SERVER_ERROR, |
||
61 | |||
62 | self::RESPONSE_UNKNOWN_ERROR => Result::STATUS_UNKNOWN_ERROR, |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * Status messages mapping. |
||
67 | * |
||
68 | * @var array |
||
69 | */ |
||
70 | protected static $statusMessageMap = [ |
||
71 | self::RESPONSE_OK => 'OK', |
||
72 | |||
73 | self::RESPONSE_MISSING_DEVICE_TOKEN => 'Missing Device Token', |
||
74 | self::RESPONSE_MISSING_TOPIC => 'Missing Topic', |
||
75 | self::RESPONSE_MISSING_PAYLOAD => 'Missing Payload', |
||
76 | self::RESPONSE_INVALID_TOKEN_SIZE => 'Invalid Token Size', |
||
77 | self::RESPONSE_INVALID_TOPIC_SIZE => 'Invalid Topic Size', |
||
78 | self::RESPONSE_INVALID_PAYLOAD_SIZE => 'Invalid Payload Size', |
||
79 | |||
80 | self::RESPONSE_INVALID_TOKEN => 'Invalid Token', |
||
81 | |||
82 | self::RESPONSE_PROCESSING_ERROR => 'Processing Error', |
||
83 | self::RESPONSE_UNAVAILABLE => 'Server Unavailable', |
||
84 | |||
85 | self::RESPONSE_UNKNOWN_ERROR => 'Unknown Error', |
||
86 | ]; |
||
87 | |||
88 | /** |
||
89 | * APNS service factory. |
||
90 | * |
||
91 | * @var Factory |
||
92 | */ |
||
93 | protected $factory; |
||
94 | |||
95 | /** |
||
96 | * Push service client. |
||
97 | * |
||
98 | * @var \ZendService\Apple\Apns\Client\Message |
||
99 | */ |
||
100 | protected $pushClient; |
||
101 | |||
102 | /** |
||
103 | * Feedback service client. |
||
104 | * |
||
105 | * @var \ZendService\Apple\Apns\Client\Feedback |
||
106 | */ |
||
107 | protected $feedbackClient; |
||
108 | |||
109 | /** |
||
110 | * APNS service adapter constructor. |
||
111 | * |
||
112 | * @param array $parameters |
||
113 | * @param Factory $factory |
||
|
|||
114 | * @param bool $sandbox |
||
115 | * |
||
116 | * @throws AdapterException |
||
117 | */ |
||
118 | public function __construct(array $parameters = [], $sandbox = false, Factory $factory = null) |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | * |
||
141 | * @throws \InvalidArgumentException |
||
142 | * @throws \Jgut\Tify\Exception\AdapterException |
||
143 | * @throws \ZendService\Apple\Exception\RuntimeException |
||
144 | */ |
||
145 | public function push(Notification $notification) |
||
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | * |
||
179 | * @throws \InvalidArgumentException |
||
180 | * @throws \Jgut\Tify\Exception\AdapterException |
||
181 | * @throws \Jgut\Tify\Exception\NotificationException |
||
182 | */ |
||
183 | public function feedback() |
||
210 | |||
211 | /** |
||
212 | * Get opened push service client. |
||
213 | * |
||
214 | * @throws AdapterException |
||
215 | * |
||
216 | * @return \ZendService\Apple\Apns\Client\Message |
||
217 | */ |
||
218 | protected function getPushClient() |
||
230 | |||
231 | /** |
||
232 | * Get opened feedback service client. |
||
233 | * |
||
234 | * @throws AdapterException |
||
235 | * |
||
236 | * @return \ZendService\Apple\Apns\Client\Feedback |
||
237 | */ |
||
238 | protected function getFeedbackClient() |
||
250 | |||
251 | /** |
||
252 | * Get service formatted push message. |
||
253 | * |
||
254 | * @param Notification $notification |
||
255 | * |
||
256 | * @throws \ZendService\Apple\Exception\RuntimeException |
||
257 | * |
||
258 | * @return \Generator<\ZendService\Apple\Apns\Message> |
||
259 | */ |
||
260 | protected function getPushMessage(Notification $notification) |
||
268 | |||
269 | /** |
||
270 | * Extract error code from exception. |
||
271 | * |
||
272 | * @param ApnsRuntimeException $exception |
||
273 | * |
||
274 | * @return int |
||
275 | */ |
||
276 | protected function getErrorCodeFromException(ApnsRuntimeException $exception) |
||
286 | |||
287 | /** |
||
288 | * {@inheritdoc} |
||
289 | */ |
||
290 | protected function getDefinedParameters() |
||
294 | |||
295 | /** |
||
296 | * {@inheritdoc} |
||
297 | */ |
||
298 | protected function getDefaultParameters() |
||
304 | |||
305 | /** |
||
306 | * {@inheritdoc} |
||
307 | */ |
||
308 | protected function getRequiredParameters() |
||
312 | |||
313 | /** |
||
314 | * Disconnect clients. |
||
315 | * |
||
316 | * @codeCoverageIgnore |
||
317 | */ |
||
318 | public function __destruct() |
||
328 | } |
||
329 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.