1 | <?php |
||
32 | abstract class AbstractProvider { |
||
33 | |||
34 | use RateLimitTrait; |
||
35 | |||
36 | /** |
||
37 | * Endpoint path. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | const ENDPOINT_PATH = "https://api.pexels.com"; |
||
42 | |||
43 | /** |
||
44 | * Authorization. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | private $authorization; |
||
49 | |||
50 | /** |
||
51 | * Debug. |
||
52 | * |
||
53 | * @var bool |
||
54 | */ |
||
55 | private $debug; |
||
56 | |||
57 | /** |
||
58 | * Logger. |
||
59 | * |
||
60 | * @var LoggerInterface |
||
61 | */ |
||
62 | private $logger; |
||
63 | |||
64 | /** |
||
65 | * Constructor. |
||
66 | * |
||
67 | * @param string $authorization The authorization. |
||
68 | * @param LoggerInterface|null $logger The logger. |
||
69 | */ |
||
70 | public function __construct($authorization = null, LoggerInterface $logger = null) { |
||
75 | |||
76 | /** |
||
77 | * Build the configuration. |
||
78 | * |
||
79 | * @return array Returns the configuration. |
||
80 | */ |
||
81 | private function buildConfiguration() { |
||
92 | |||
93 | /** |
||
94 | * Build a resource path. |
||
95 | * |
||
96 | * @param AbstractRequest $request The request. |
||
97 | * @return string Returns the resource path. |
||
98 | * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
||
99 | */ |
||
100 | private function buildResourcePath(AbstractRequest $request) { |
||
112 | |||
113 | /** |
||
114 | * Call the API. |
||
115 | * |
||
116 | * @param string $uri The URI. |
||
117 | * @param array $queryData The query data. |
||
118 | * @return string Returns the raw response. |
||
119 | * @throws APIException Throws an API exception if an error occurs. |
||
120 | * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
||
121 | */ |
||
122 | private function callAPI($uri, array $queryData) { |
||
151 | |||
152 | /** |
||
153 | * Call the API. |
||
154 | * |
||
155 | * @param AbstractRequest $request The request. |
||
156 | * @param array $queryData The query data. |
||
157 | * @return string Returns the raw response. |
||
158 | * @throws APIException Throws an API exception if an error occurs. |
||
159 | * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
||
160 | */ |
||
161 | protected function callAPIWithRequest(AbstractRequest $request, array $queryData) { |
||
173 | |||
174 | /** |
||
175 | * Call the API. |
||
176 | * |
||
177 | * @param PaginateResponseInterface $response The request. |
||
178 | * @param bool $nextPage Next page ?. |
||
179 | * @return string Returns the raw response. |
||
180 | * @throws APIException Throws an API exception if an error occurs. |
||
181 | * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing. |
||
182 | */ |
||
183 | protected function callAPIWithResponse(PaginateResponseInterface $response, $nextPage) { |
||
198 | |||
199 | /** |
||
200 | * Get the authorization. |
||
201 | * |
||
202 | * @return string Returns the authorization. |
||
203 | */ |
||
204 | public function getAuthorization() { |
||
207 | |||
208 | /** |
||
209 | * Get the debug. |
||
210 | * |
||
211 | * @return bool Returns the debug. |
||
212 | */ |
||
213 | public function getDebug() { |
||
216 | |||
217 | /** |
||
218 | * Get the logger. |
||
219 | * |
||
220 | * @return LoggerInterface Returns the logger. |
||
221 | */ |
||
222 | public function getLogger() { |
||
225 | |||
226 | /** |
||
227 | * Log. |
||
228 | * |
||
229 | * @param string $message The message. |
||
230 | * @param array $context The context. |
||
231 | * @return AbstractProvider Returns this provider. |
||
232 | */ |
||
233 | protected function log($message, array $context) { |
||
239 | |||
240 | /** |
||
241 | * Set the authorization. |
||
242 | * |
||
243 | * @param string $authorization The authorization. |
||
244 | * @return AbstractProvider Returns this provider. |
||
245 | */ |
||
246 | public function setAuthorization($authorization) { |
||
250 | |||
251 | /** |
||
252 | * Set the debug. |
||
253 | * |
||
254 | * @param bool $debug The debug. |
||
255 | * @return AbstractProvider Returns this provider. |
||
256 | */ |
||
257 | public function setDebug($debug) { |
||
261 | |||
262 | /** |
||
263 | * Set the logger. |
||
264 | * |
||
265 | * @param LoggerInterface|null $logger The logger |
||
266 | * @return AbstractProvider Returns this provider |
||
267 | */ |
||
268 | protected function setLogger(LoggerInterface $logger = null) { |
||
272 | } |
||
273 |