1 | <?php |
||
25 | class Authorization |
||
26 | { |
||
27 | use Caches; |
||
28 | |||
29 | const CACHE_KEY_ACCESS_TOKEN = 'easywechat.open_platform.authorizer_access_token'; |
||
30 | const CACHE_KEY_REFRESH_TOKEN = 'easywechat.open_platform.authorizer_refresh_token'; |
||
31 | |||
32 | /** |
||
33 | * Authorizer API. |
||
34 | * |
||
35 | * @var Authorizer |
||
36 | */ |
||
37 | private $authorizer; |
||
38 | |||
39 | /** |
||
40 | * Open Platform App Id, aka, Component App Id. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $appId; |
||
45 | |||
46 | /** |
||
47 | * Authorizer App Id. |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | private $authorizerAppId; |
||
52 | |||
53 | /** |
||
54 | * Auth code. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | private $authCode; |
||
59 | |||
60 | public function __construct(Authorizer $authorizer, $appId, |
||
67 | |||
68 | /** |
||
69 | * Sets the authorizer app id. |
||
70 | * |
||
71 | * @param string $authorizerAppId |
||
72 | */ |
||
73 | public function setAuthorizerAppId($authorizerAppId) |
||
77 | |||
78 | /** |
||
79 | * Gets the authorizer app id, or throws if not found. |
||
80 | * |
||
81 | * @return string |
||
82 | * @throws Exception |
||
83 | */ |
||
84 | public function getAuthorizerAppId() |
||
94 | |||
95 | /** |
||
96 | * Sets the auth code. |
||
97 | * |
||
98 | * @param $code |
||
99 | */ |
||
100 | public function setAuthCode($code) |
||
104 | |||
105 | /** |
||
106 | * Gets the auth code. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getAuthCode() |
||
114 | |||
115 | /** |
||
116 | * Sets the auth info from the message of the auth event sent by WeChat. |
||
117 | * |
||
118 | * @param Collection $message |
||
119 | */ |
||
120 | public function setFromAuthMessage(Collection $message) |
||
129 | |||
130 | /** |
||
131 | * Handles authorization: calls the API, saves the tokens. |
||
132 | * |
||
133 | * @return Collection |
||
134 | */ |
||
135 | public function handleAuthorization() |
||
152 | |||
153 | /** |
||
154 | * Handles the authorizer access token: calls the API, saves the token. |
||
155 | * |
||
156 | * @return string The authorizer access token. |
||
157 | */ |
||
158 | public function handleAuthorizerAccessToken() |
||
169 | |||
170 | /** |
||
171 | * Gets the authorization information. |
||
172 | * Like authorizer app id, access token, refresh token, function scope, etc. |
||
173 | * |
||
174 | * @return Collection |
||
175 | */ |
||
176 | public function getAuthorizationInfo() |
||
185 | |||
186 | /** |
||
187 | * Gets the authorizer information. |
||
188 | * Like authorizer name, logo, business, etc. |
||
189 | * |
||
190 | * @return Collection |
||
191 | */ |
||
192 | public function getAuthorizerInfo() |
||
201 | |||
202 | /** |
||
203 | * Saves the authorizer access token in cache. |
||
204 | * |
||
205 | * @param Collection|array $data Array structure from WeChat API result. |
||
206 | */ |
||
207 | public function saveAuthorizerAccessToken($data) |
||
215 | |||
216 | /** |
||
217 | * Gets the authorizer access token. |
||
218 | * |
||
219 | * @return string |
||
220 | */ |
||
221 | public function getAuthorizerAccessToken() |
||
225 | |||
226 | /** |
||
227 | * Saves the authorizer refresh token in cache. |
||
228 | * |
||
229 | * @param Collection|array $data Array structure from WeChat API result. |
||
230 | */ |
||
231 | public function saveAuthorizerRefreshToken($data) |
||
237 | |||
238 | /** |
||
239 | * Gets the authorizer refresh token. |
||
240 | * |
||
241 | * @return string |
||
242 | * @throws Exception When refresh token is not present. |
||
243 | */ |
||
244 | public function getAuthorizerRefreshToken() |
||
254 | |||
255 | /** |
||
256 | * Removes the authorizer access token from cache. |
||
257 | */ |
||
258 | public function removeAuthorizerAccessToken() |
||
262 | |||
263 | /** |
||
264 | * Removes the authorizer refresh token from cache. |
||
265 | */ |
||
266 | public function removeAuthorizerRefreshToken() |
||
270 | |||
271 | /** |
||
272 | * Gets the authorizer access token cache key. |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | public function getAuthorizerAccessTokenKey() |
||
282 | |||
283 | /** |
||
284 | * Gets the authorizer refresh token cache key. |
||
285 | * |
||
286 | * @return string |
||
287 | */ |
||
288 | public function getAuthorizerRefreshTokenKey() |
||
294 | |||
295 | } |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):