1 | <?php |
||
22 | class GcmAdapter extends AbstractAdapter implements PushAdapter |
||
23 | { |
||
24 | const RESULT_INTERNAL_SERVER_ERROR = 'InternalServerError'; |
||
25 | const RESULT_SERVER_UNAVAILABLE = 'ServerUnavailable'; |
||
26 | const RESULT_AUTHENTICATION_ERROR = 'AuthenticationError'; |
||
27 | const RESULT_INVALID_MESSAGE = 'InvalidMessage'; |
||
28 | const RESULT_BAD_FORMATTED_RESPONSE = 'BadFormattedResponse'; |
||
29 | const RESULT_UNKNOWN = 'Unknown'; |
||
30 | |||
31 | /** |
||
32 | * Status codes mapping. |
||
33 | * |
||
34 | * @see https://developers.google.com/cloud-messaging/http-server-ref |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected static $statusCodes = [ |
||
39 | 'MissingRegistration' => 'Missing Registration Token', |
||
40 | 'InvalidRegistration' => 'Invalid Registration Token', |
||
41 | 'NotRegistered' => 'Unregistered Device', |
||
42 | 'InvalidPackageName' => 'Invalid Package Name', |
||
43 | 'MismatchSenderId' => 'Mismatched Sender', |
||
44 | 'MessageTooBig' => 'Message Too Big', |
||
45 | 'InvalidDataKey' => 'Invalid Data Key', |
||
46 | 'InvalidTtl' => 'Invalid Time to Live', |
||
47 | 'Unavailable' => 'Timeout', |
||
48 | 'InternalServerError' => 'Internal Server Error', |
||
49 | 'DeviceMessageRateExceeded' => 'Device Message Rate Exceeded', |
||
50 | 'TopicsMessageRateExceeded' => 'Topics Message Rate Exceeded', |
||
51 | self::RESULT_INTERNAL_SERVER_ERROR => 'Internal Server Error', |
||
52 | self::RESULT_SERVER_UNAVAILABLE => 'Server Unavailable', |
||
53 | self::RESULT_AUTHENTICATION_ERROR => 'Authentication Error', |
||
54 | self::RESULT_INVALID_MESSAGE => 'Invalid message', |
||
55 | self::RESULT_BAD_FORMATTED_RESPONSE => 'Bad Formatted Response', |
||
56 | self::RESULT_UNKNOWN => 'Unknown Error', |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * GCM service builder. |
||
61 | * |
||
62 | * @var \Jgut\Tify\Adapter\Gcm\GcmBuilder |
||
63 | */ |
||
64 | protected $builder; |
||
65 | |||
66 | /** |
||
67 | * @var \ZendService\Google\Gcm\Client |
||
68 | */ |
||
69 | protected $pushClient; |
||
70 | |||
71 | /** |
||
72 | * @param array $parameters |
||
73 | * @param \Jgut\Tify\Adapter\Gcm\GcmBuilder|null $builder |
||
74 | * |
||
75 | * @throws \Jgut\Tify\Exception\AdapterException |
||
76 | */ |
||
77 | public function __construct(array $parameters = [], GcmBuilder $builder = null) |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | * |
||
92 | * @throws \InvalidArgumentException |
||
93 | * @throws \ZendService\Google\Exception\InvalidArgumentException |
||
94 | * @throws \ZendService\Google\Exception\RuntimeException |
||
95 | */ |
||
96 | public function push(Notification $notification) |
||
138 | |||
139 | /** |
||
140 | * Get opened client. |
||
141 | * |
||
142 | * @return \ZendService\Google\Gcm\Client |
||
143 | */ |
||
144 | protected function getPushClient() |
||
152 | |||
153 | /** |
||
154 | * Get service formatted push messages. |
||
155 | * |
||
156 | * @param \Jgut\Tify\Notification $notification |
||
157 | * |
||
158 | * @throws \ZendService\Google\Exception\InvalidArgumentException |
||
159 | * @throws \ZendService\Google\Exception\RuntimeException |
||
160 | * |
||
161 | * @return \Generator |
||
162 | */ |
||
163 | protected function getPushMessages(Notification $notification) |
||
176 | |||
177 | /** |
||
178 | * Extract error code from exception. |
||
179 | * |
||
180 | * @param \ZendService\Google\Exception\RuntimeException $exception |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | protected function getErrorCodeFromException(GcmRuntimeException $exception) |
||
210 | |||
211 | /** |
||
212 | * {@inheritdoc} |
||
213 | */ |
||
214 | protected function getDefinedParameters() |
||
218 | |||
219 | /** |
||
220 | * {@inheritdoc} |
||
221 | */ |
||
222 | protected function getRequiredParameters() |
||
226 | } |
||
227 |