1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2015 Alexey Maslov <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace alxmsl\Google\GCM\Response; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class for message delivery status |
22
|
|
|
* @author alxmsl |
23
|
|
|
* @date 5/28/13 |
24
|
|
|
*/ |
25
|
|
|
final class Status { |
26
|
|
|
/** |
27
|
|
|
* Error constants |
28
|
|
|
*/ |
29
|
|
|
const STATUS_UNAVAILABLE = 'Unavailable', |
30
|
|
|
STATUS_NOT_REGISTERED = 'NotRegistered', |
31
|
|
|
STATUS_MISSING_REGISTRATION = 'MissingRegistration', |
32
|
|
|
STATUS_INVALID_REGISTRATION = 'InvalidRegistration', |
33
|
|
|
STATUS_MISMATCH_SENDER_ID = 'MismatchSenderId', |
34
|
|
|
STATUS_MESSAGE_TOO_BIG = 'MessageTooBig', |
35
|
|
|
STATUS_INVALID_DATA_KEY = 'InvalidDataKey', |
36
|
|
|
STATUS_INVALID_TTL = 'InvalidTtl', |
37
|
|
|
STATUS_INTERNAL_SERVER_ERROR = 'InternalServerError'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string message identifier |
41
|
|
|
*/ |
42
|
|
|
private $messageId = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string canonical device identifier |
46
|
|
|
*/ |
47
|
|
|
private $canonicalId = ''; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string error code |
51
|
|
|
*/ |
52
|
|
|
private $error = ''; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Error code setter |
56
|
|
|
* @param string $error error code |
57
|
|
|
* @return Status self |
58
|
|
|
*/ |
59
|
3 |
|
public function setError($error) { |
60
|
3 |
|
$this->error = (string) $error; |
61
|
3 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Error code getter |
66
|
|
|
* @return string error code |
67
|
|
|
*/ |
68
|
4 |
|
public function getError() { |
69
|
4 |
|
return $this->error; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Message identifier setter |
74
|
|
|
* @param string $messageId message identifier |
75
|
|
|
* @return Status self |
76
|
|
|
*/ |
77
|
4 |
|
public function setMessageId($messageId) { |
78
|
4 |
|
$this->messageId = (string) $messageId; |
79
|
4 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Message identifier getter |
84
|
|
|
* @return string message identifier |
85
|
|
|
*/ |
86
|
3 |
|
public function getMessageId() { |
87
|
3 |
|
return $this->messageId; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Canonical identifier setter |
92
|
|
|
* @param string $registrationId canonical identifier |
93
|
|
|
* @return Status self |
94
|
|
|
*/ |
95
|
4 |
|
public function setCanonicalId($registrationId) { |
96
|
4 |
|
$this->canonicalId = (string) $registrationId; |
97
|
4 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Canonical identifier getter |
102
|
|
|
* @return string canonical identifier |
103
|
|
|
*/ |
104
|
3 |
|
public function getCanonicalId() { |
105
|
3 |
|
return $this->canonicalId; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Check status for new device registration identifier |
110
|
|
|
* @return bool true when status has new device registration identifier |
111
|
|
|
*/ |
112
|
3 |
|
public function hasCanonicalId() { |
113
|
3 |
|
return !empty($this->canonicalId); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Check status for need to remove device registration identifier |
118
|
|
|
* @return bool true when need to remove device registration identifier |
119
|
|
|
*/ |
120
|
3 |
|
public function mustRemove() { |
121
|
3 |
|
return $this->getError() == self::STATUS_NOT_REGISTERED; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Check status for can to retry message sending |
126
|
|
|
* @return bool true when can to retry message sending |
127
|
|
|
*/ |
128
|
3 |
|
public function canRetry() { |
129
|
3 |
|
return $this->getError() == self::STATUS_UNAVAILABLE |
130
|
3 |
|
|| $this->getError() == self::STATUS_INTERNAL_SERVER_ERROR; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|