1 | <?php |
||
30 | abstract class AbstractReportingCloud |
||
31 | { |
||
32 | /** |
||
33 | * Default date/time format of backend is 'ISO 8601' |
||
34 | * |
||
35 | * Note, last letter is 'P' and not 'O': |
||
36 | * |
||
37 | * O - Difference to Greenwich time (GMT) in hours (e.g. +0200) |
||
38 | * P - Difference to Greenwich time (GMT) with colon between hours and minutes (e.g. +02:00) |
||
39 | * |
||
40 | * Backend uses the 'P' variant |
||
41 | * |
||
42 | * @const DEFAULT_DATE_FORMAT |
||
43 | */ |
||
44 | const DEFAULT_DATE_FORMAT = 'Y-m-d\TH:i:sP'; |
||
45 | |||
46 | /** |
||
47 | * Default time zone of backend |
||
48 | * |
||
49 | * @const DEFAULT_TIME_ZONE |
||
50 | */ |
||
51 | const DEFAULT_TIME_ZONE = 'UTC'; |
||
52 | |||
53 | /** |
||
54 | * Default base URI of backend |
||
55 | * |
||
56 | * @const DEFAULT_BASE_URI |
||
57 | */ |
||
58 | const DEFAULT_BASE_URI = 'https://api.reporting.cloud'; |
||
59 | |||
60 | /** |
||
61 | * Default version string of backend |
||
62 | * |
||
63 | * @const DEFAULT_VERSION |
||
64 | */ |
||
65 | const DEFAULT_VERSION = 'v1'; |
||
66 | |||
67 | /** |
||
68 | * Default timeout of backend in seconds |
||
69 | * |
||
70 | * @const DEFAULT_TIMEOUT |
||
71 | */ |
||
72 | const DEFAULT_TIMEOUT = 120; // seconds |
||
73 | |||
74 | /** |
||
75 | * Default debug flag of REST client |
||
76 | * |
||
77 | * @const DEFAULT_DEBUG |
||
78 | */ |
||
79 | const DEFAULT_DEBUG = false; |
||
80 | |||
81 | /** |
||
82 | * Backend username |
||
83 | * |
||
84 | * @var string |
||
85 | */ |
||
86 | protected $username; |
||
87 | |||
88 | /** |
||
89 | * Backend password |
||
90 | * |
||
91 | * @var string |
||
92 | */ |
||
93 | protected $password; |
||
94 | |||
95 | /** |
||
96 | * Backend base URI |
||
97 | * |
||
98 | * @var string |
||
99 | */ |
||
100 | protected $baseUri; |
||
101 | |||
102 | /** |
||
103 | * Backend version string |
||
104 | * |
||
105 | * @var string |
||
106 | */ |
||
107 | protected $version; |
||
108 | |||
109 | /** |
||
110 | * Backend timeout in seconds |
||
111 | * |
||
112 | * @var integer |
||
113 | */ |
||
114 | protected $timeout; |
||
115 | |||
116 | /** |
||
117 | * REST client to backend |
||
118 | * |
||
119 | * @var Client |
||
120 | */ |
||
121 | protected $client; |
||
122 | |||
123 | /** |
||
124 | * Debug flag of REST client |
||
125 | * |
||
126 | * @var boolean |
||
127 | */ |
||
128 | protected $debug; |
||
129 | |||
130 | /** |
||
131 | * AbstractReportingCloud constructor |
||
132 | * |
||
133 | * @param array $options |
||
134 | */ |
||
135 | 46 | public function __construct($options = []) |
|
161 | |||
162 | /** |
||
163 | * Return the REST client of the backend web service |
||
164 | * |
||
165 | * @return \GuzzleHttp\Client |
||
166 | */ |
||
167 | 14 | public function getClient() |
|
189 | |||
190 | /** |
||
191 | * Set the REST client of the backend web service |
||
192 | * |
||
193 | * @param Client $client REST client |
||
194 | * |
||
195 | * @return ReportingCloud |
||
196 | */ |
||
197 | 14 | public function setClient(Client $client) |
|
203 | |||
204 | /** |
||
205 | * Return the base URI of the backend web service |
||
206 | * |
||
207 | * @return string |
||
208 | */ |
||
209 | 18 | public function getBaseUri() |
|
217 | |||
218 | /** |
||
219 | * Set the base URI of the backend web service |
||
220 | * |
||
221 | * @param string $baseUri Base URI |
||
222 | * |
||
223 | * @return ReportingCloud |
||
224 | */ |
||
225 | 18 | public function setBaseUri($baseUri) |
|
231 | |||
232 | /** |
||
233 | * Get the timeout (in seconds) of the backend web service |
||
234 | * |
||
235 | * @return integer |
||
236 | */ |
||
237 | 17 | public function getTimeout() |
|
245 | |||
246 | /** |
||
247 | * Set the timeout (in seconds) of the backend web service |
||
248 | * |
||
249 | * @param integer $timeout Timeout |
||
250 | * |
||
251 | * @return ReportingCloud |
||
252 | */ |
||
253 | 17 | public function setTimeout($timeout) |
|
259 | |||
260 | /** |
||
261 | * Return the username |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | 17 | public function getUsername() |
|
269 | |||
270 | /** |
||
271 | * Set the username |
||
272 | * |
||
273 | * @param string $username Username |
||
274 | * |
||
275 | * @return ReportingCloud |
||
276 | */ |
||
277 | 43 | public function setUsername($username) |
|
283 | |||
284 | /** |
||
285 | * Return the password |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | 17 | public function getPassword() |
|
293 | |||
294 | /** |
||
295 | * Set the password |
||
296 | * |
||
297 | * @param string $password Password |
||
298 | * |
||
299 | * @return ReportingCloud |
||
300 | */ |
||
301 | 43 | public function setPassword($password) |
|
307 | |||
308 | /** |
||
309 | * Return the debug flag |
||
310 | * |
||
311 | * @return mixed |
||
312 | */ |
||
313 | 17 | public function getDebug() |
|
321 | |||
322 | /** |
||
323 | * Set the debug flag |
||
324 | * |
||
325 | * @param boolean $debug Debug flag |
||
326 | * |
||
327 | * @return ReportingCloud |
||
328 | */ |
||
329 | 17 | public function setDebug($debug) |
|
335 | |||
336 | /** |
||
337 | * Construct URI with version number |
||
338 | * |
||
339 | * @param string $uri URI |
||
340 | * |
||
341 | * @return string |
||
342 | */ |
||
343 | 13 | protected function uri($uri) |
|
347 | |||
348 | /** |
||
349 | * Get the version string of the backend web service |
||
350 | * |
||
351 | * @return string |
||
352 | */ |
||
353 | 16 | public function getVersion() |
|
361 | |||
362 | /** |
||
363 | * Set the version string of the backend web service |
||
364 | * |
||
365 | * @param string $version Version string |
||
366 | * |
||
367 | * @return ReportingCloud |
||
368 | */ |
||
369 | 2 | public function setVersion($version) |
|
375 | |||
376 | /** |
||
377 | * Request the URI with options |
||
378 | * |
||
379 | * @param string $method HTTP method |
||
380 | * @param string $uri URI |
||
381 | * @param array $options Options |
||
382 | * |
||
383 | * @return mixed|null|\Psr\Http\Message\ResponseInterface |
||
384 | * |
||
385 | * @throws RuntimeException |
||
386 | */ |
||
387 | 13 | protected function request($method, $uri, $options) |
|
414 | |||
415 | /** |
||
416 | * Using the passed propertyMap, recursively normalizes the keys of the passed array |
||
417 | * |
||
418 | * @param array $array Array |
||
419 | * @param PropertyMap $propertyMap PropertyMap |
||
420 | * |
||
421 | * @return array |
||
422 | */ |
||
423 | 3 | protected function normalizeArrayKeys($array, PropertyMap $propertyMap) |
|
440 | |||
441 | /** |
||
442 | * Assemble MergeSettings array to pass to ReportingCloud |
||
443 | * |
||
444 | * @param array $mergeSettings MergeSettings array |
||
445 | * |
||
446 | * @return array |
||
447 | */ |
||
448 | 4 | protected function assembleMergeSettings($mergeSettings) |
|
471 | |||
472 | } |