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