1 | <?php |
||
23 | class GcmAdapter extends AbstractAdapter implements PushAdapter |
||
24 | { |
||
25 | const PARAMETER_API_KEY = 'api_key'; |
||
26 | |||
27 | const RESPONSE_OK = 'OK'; |
||
28 | const RESPONSE_MISSING_REGISTRATION = 'MissingRegistration'; |
||
29 | const RESPONSE_INVALID_REGISTRATION = 'InvalidRegistration'; |
||
30 | const RESPONSE_NOT_REGISTERED = 'NotRegistered'; |
||
31 | const RESPONSE_INVALID_PACKAGE_NAME = 'InvalidPackageName'; |
||
32 | const RESPONSE_MISMATCH_SENDER_ID = 'MismatchSenderId'; |
||
33 | const RESPONSE_MESSAGE_TOO_BIG = 'MessageTooBig'; |
||
34 | const RESPONSE_INVALID_DATA_KEY = 'InvalidDataKey'; |
||
35 | const RESPONSE_INVALID_TTL = 'InvalidTtl'; |
||
36 | const RESPONSE_TIMEOUT = 'Timeout'; |
||
37 | const RESPONSE_INTERNAL_SERVER_ERROR = 'InternalServerError'; |
||
38 | const RESPONSE_DEVICE_MESSAGE_RATE_EXCEEDED = 'DeviceMessageRateExceeded'; |
||
39 | const RESPONSE_TOPIC_MESSAGE_RATE_EXCEEDED = 'TopicsMessageRateExceeded'; |
||
40 | const RESPONSE_SERVER_UNAVAILABLE = 'ServerUnavailable'; |
||
41 | const RESPONSE_AUTHENTICATION_ERROR = 'AuthenticationError'; |
||
42 | const RESPONSE_INVALID_MESSAGE = 'InvalidMessage'; |
||
43 | const RESPONSE_BADLY_FORMATTED_RESPONSE = 'BadlyFormattedResponse'; |
||
44 | const RESPONSE_UNKNOWN_ERROR = 'Unknown'; |
||
45 | |||
46 | /** |
||
47 | * Status codes mapping. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected static $statusCodeMap = [ |
||
52 | self::RESPONSE_OK => Result::STATUS_SUCCESS, |
||
53 | |||
54 | self::RESPONSE_MISSING_REGISTRATION => Result::STATUS_INVALID_MESSAGE, |
||
55 | self::RESPONSE_INVALID_PACKAGE_NAME => Result::STATUS_INVALID_MESSAGE, |
||
56 | self::RESPONSE_MISMATCH_SENDER_ID => Result::STATUS_INVALID_MESSAGE, |
||
57 | self::RESPONSE_MESSAGE_TOO_BIG => Result::STATUS_INVALID_MESSAGE, |
||
58 | self::RESPONSE_INVALID_DATA_KEY => Result::STATUS_INVALID_MESSAGE, |
||
59 | self::RESPONSE_INVALID_TTL => Result::STATUS_INVALID_MESSAGE, |
||
60 | self::RESPONSE_INVALID_MESSAGE => Result::STATUS_INVALID_MESSAGE, |
||
61 | |||
62 | self::RESPONSE_INVALID_REGISTRATION => Result::STATUS_INVALID_DEVICE, |
||
63 | self::RESPONSE_NOT_REGISTERED => Result::STATUS_INVALID_DEVICE, |
||
64 | |||
65 | self::RESPONSE_DEVICE_MESSAGE_RATE_EXCEEDED => Result::STATUS_RATE_ERROR, |
||
66 | self::RESPONSE_TOPIC_MESSAGE_RATE_EXCEEDED => Result::STATUS_RATE_ERROR, |
||
67 | |||
68 | self::RESPONSE_AUTHENTICATION_ERROR => Result::STATUS_AUTH_ERROR, |
||
69 | |||
70 | self::RESPONSE_TIMEOUT => Result::STATUS_SERVER_ERROR, |
||
71 | self::RESPONSE_INTERNAL_SERVER_ERROR => Result::STATUS_SERVER_ERROR, |
||
72 | self::RESPONSE_SERVER_UNAVAILABLE => Result::STATUS_SERVER_ERROR, |
||
73 | self::RESPONSE_BADLY_FORMATTED_RESPONSE => Result::STATUS_SERVER_ERROR, |
||
74 | |||
75 | self::RESPONSE_UNKNOWN_ERROR => Result::STATUS_UNKNOWN_ERROR, |
||
76 | ]; |
||
77 | |||
78 | /** |
||
79 | * Status messages mapping. |
||
80 | * |
||
81 | * @see https://developers.google.com/cloud-messaging/http-server-ref |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | protected static $statusMessageMap = [ |
||
86 | self::RESPONSE_OK => 'OK', |
||
87 | |||
88 | self::RESPONSE_MISSING_REGISTRATION => 'Missing Registration Token', |
||
89 | self::RESPONSE_INVALID_PACKAGE_NAME => 'Invalid Package Name', |
||
90 | self::RESPONSE_MISMATCH_SENDER_ID => 'Mismatched Sender', |
||
91 | self::RESPONSE_MESSAGE_TOO_BIG => 'Message Too Big', |
||
92 | self::RESPONSE_INVALID_DATA_KEY => 'Invalid Data Key', |
||
93 | self::RESPONSE_INVALID_TTL => 'Invalid Time to Live', |
||
94 | self::RESPONSE_INVALID_MESSAGE => 'Invalid message', |
||
95 | |||
96 | self::RESPONSE_INVALID_REGISTRATION => 'Invalid Registration Token', |
||
97 | self::RESPONSE_NOT_REGISTERED => 'Unregistered Device', |
||
98 | |||
99 | self::RESPONSE_DEVICE_MESSAGE_RATE_EXCEEDED => 'Device Message Rate Exceeded', |
||
100 | self::RESPONSE_TOPIC_MESSAGE_RATE_EXCEEDED => 'Topics Message Rate Exceeded', |
||
101 | |||
102 | self::RESPONSE_AUTHENTICATION_ERROR => 'Authentication Error', |
||
103 | |||
104 | self::RESPONSE_TIMEOUT => 'Timeout', |
||
105 | self::RESPONSE_INTERNAL_SERVER_ERROR => 'Internal Server Error', |
||
106 | self::RESPONSE_SERVER_UNAVAILABLE => 'Server Unavailable', |
||
107 | self::RESPONSE_BADLY_FORMATTED_RESPONSE => 'Bad Formatted Response', |
||
108 | |||
109 | self::RESPONSE_UNKNOWN_ERROR => 'Unknown Error', |
||
110 | ]; |
||
111 | |||
112 | /** |
||
113 | * GCM service factory. |
||
114 | * |
||
115 | * @var Factory |
||
116 | */ |
||
117 | protected $factory; |
||
118 | |||
119 | /** |
||
120 | * Push service client. |
||
121 | * |
||
122 | * @var \ZendService\Google\Gcm\Client |
||
123 | */ |
||
124 | protected $pushClient; |
||
125 | |||
126 | /** |
||
127 | * GCM service adapter constructor. |
||
128 | * |
||
129 | * @param array $parameters |
||
130 | * @param bool $sandbox |
||
131 | * @param Factory $factory |
||
|
|||
132 | * |
||
133 | * @throws \Jgut\Tify\Exception\AdapterException |
||
134 | */ |
||
135 | public function __construct(array $parameters = [], $sandbox = false, Factory $factory = null) |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | * |
||
151 | * @throws \InvalidArgumentException |
||
152 | * @throws \ZendService\Google\Exception\InvalidArgumentException |
||
153 | * @throws \ZendService\Google\Exception\RuntimeException |
||
154 | */ |
||
155 | public function push(Notification $notification) |
||
201 | |||
202 | /** |
||
203 | * Get opened push client. |
||
204 | * |
||
205 | * @return \ZendService\Google\Gcm\Client |
||
206 | */ |
||
207 | protected function getPushClient() |
||
215 | |||
216 | /** |
||
217 | * Get service formatted push message. |
||
218 | * |
||
219 | * @param Notification $notification |
||
220 | * |
||
221 | * @throws \ZendService\Google\Exception\InvalidArgumentException |
||
222 | * @throws \ZendService\Google\Exception\RuntimeException |
||
223 | * |
||
224 | * @return \Generator<\ZendService\Google\Gcm\Message> |
||
225 | */ |
||
226 | protected function getPushMessage(Notification $notification) |
||
245 | |||
246 | /** |
||
247 | * Extract error code from exception. |
||
248 | * |
||
249 | * @param GcmRuntimeException $exception |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | protected function getErrorCodeFromException(GcmRuntimeException $exception) |
||
279 | |||
280 | /** |
||
281 | * {@inheritdoc} |
||
282 | */ |
||
283 | protected function getDefinedParameters() |
||
287 | |||
288 | /** |
||
289 | * {@inheritdoc} |
||
290 | */ |
||
291 | protected function getRequiredParameters() |
||
295 | } |
||
296 |
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.