1 | <?php |
||
35 | abstract class AbstractAPI |
||
36 | { |
||
37 | /** |
||
38 | * Http instance. |
||
39 | * |
||
40 | * @var \EasyWeChat\Core\Http |
||
41 | */ |
||
42 | protected $http; |
||
43 | |||
44 | /** |
||
45 | * The reqeust token. |
||
46 | * |
||
47 | * @var \EasyWeChat\Core\AccessToken |
||
48 | */ |
||
49 | protected $accessToken; |
||
50 | |||
51 | const GET = 'get'; |
||
52 | const POST = 'post'; |
||
53 | const JSON = 'json'; |
||
54 | |||
55 | /** |
||
56 | * Constructor. |
||
57 | * |
||
58 | * @param \EasyWeChat\Core\AccessToken $accessToken |
||
59 | */ |
||
60 | public function __construct(AccessToken $accessToken) |
||
66 | |||
67 | /** |
||
68 | * Return the http instance. |
||
69 | * |
||
70 | * @return \EasyWeChat\Core\Http |
||
71 | */ |
||
72 | public function getHttp() |
||
76 | |||
77 | /** |
||
78 | * Set the http instance. |
||
79 | * |
||
80 | * @param \EasyWeChat\Core\Http $http |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function setHttp(Http $http) |
||
90 | |||
91 | /** |
||
92 | * Return the current accessToken. |
||
93 | * |
||
94 | * @return \EasyWeChat\Core\AccessToken |
||
95 | */ |
||
96 | public function getAccessToken() |
||
100 | |||
101 | /** |
||
102 | * Set the request token. |
||
103 | * |
||
104 | * @param \EasyWeChat\Core\AccessToken $accessToken |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | public function setAccessToken(AccessToken $accessToken) |
||
114 | |||
115 | /** |
||
116 | * Parse JSON from response and check error. |
||
117 | * |
||
118 | * @param string $method |
||
119 | * @param array $args |
||
120 | * @param bool $throws |
||
121 | * |
||
122 | * @return \EasyWeChat\Support\Collection |
||
123 | */ |
||
124 | public function parseJSON($method, $args, $throws = true) |
||
136 | |||
137 | /** |
||
138 | * Set request access_token query. |
||
139 | */ |
||
140 | protected function registerHttpMiddleware() |
||
149 | |||
150 | /** |
||
151 | * Attache access token to request query. |
||
152 | * |
||
153 | * @return Closure |
||
154 | */ |
||
155 | public function accessTokenMiddleware() |
||
172 | |||
173 | /** |
||
174 | * Log the request. |
||
175 | * |
||
176 | * @return \GuzzleHttp\Middleware |
||
177 | */ |
||
178 | public function logMiddleware() |
||
185 | |||
186 | /** |
||
187 | * Return retry middleware. |
||
188 | * |
||
189 | * @return \GuzzleHttp\RetryMiddleware |
||
190 | */ |
||
191 | protected function retryMiddleware() |
||
217 | |||
218 | /** |
||
219 | * Check the array data erros, and Throw expcetion when the contents cotnains error. |
||
220 | * |
||
221 | * @param array $contents |
||
222 | * |
||
223 | * @throws \EasyWeChat\Core\Exceptions\HttpException |
||
224 | */ |
||
225 | protected function checkAndThrow(array $contents) |
||
235 | } |
||
236 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.