|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ReportingCloud PHP Wrapper |
|
5
|
|
|
* |
|
6
|
|
|
* PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH. |
|
7
|
|
|
* |
|
8
|
|
|
* @link http://www.reporting.cloud to learn more about ReportingCloud |
|
9
|
|
|
* @link https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository |
|
10
|
|
|
* @license https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md |
|
11
|
|
|
* @copyright © 2018 Text Control GmbH |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace TxTextControl\ReportingCloud; |
|
15
|
|
|
|
|
16
|
|
|
use GuzzleHttp\Client; |
|
17
|
|
|
use GuzzleHttp\RequestOptions; |
|
18
|
|
|
|
|
19
|
|
|
trait SetGetTrait |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Backend username |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $username; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Backend password |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $password; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* When true, backend prints "TEST MODE" water mark into output document, and API call does not count against quota |
|
37
|
|
|
* |
|
38
|
|
|
* @var bool |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $test; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Backend base URI |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $baseUri; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Backend version string |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $version; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Backend timeout in seconds |
|
58
|
|
|
* |
|
59
|
|
|
* @var int |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $timeout; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* REST client to backend |
|
65
|
|
|
* |
|
66
|
|
|
* @var Client |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $client; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Debug flag of REST client |
|
72
|
|
|
* |
|
73
|
|
|
* @var bool |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $debug; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Return the REST client of the backend web service |
|
79
|
|
|
* |
|
80
|
|
|
* @return \GuzzleHttp\Client |
|
81
|
|
|
*/ |
|
82
|
20 |
|
public function getClient() |
|
83
|
|
|
{ |
|
84
|
20 |
|
if (null === $this->client) { |
|
85
|
|
|
|
|
86
|
20 |
|
$credentials = sprintf('%s:%s', $this->getUsername(), $this->getPassword()); |
|
87
|
20 |
|
$authorization = sprintf('Basic %s', base64_encode($credentials)); |
|
88
|
|
|
|
|
89
|
|
|
$options = [ |
|
90
|
20 |
|
'base_uri' => $this->getBaseUri(), |
|
91
|
20 |
|
RequestOptions::TIMEOUT => $this->getTimeout(), |
|
92
|
20 |
|
RequestOptions::DEBUG => $this->getDebug(), |
|
93
|
20 |
|
RequestOptions::HEADERS => [ |
|
94
|
20 |
|
'Authorization' => $authorization, |
|
95
|
20 |
|
], |
|
96
|
20 |
|
]; |
|
97
|
|
|
|
|
98
|
20 |
|
$client = new Client($options); |
|
99
|
|
|
|
|
100
|
20 |
|
$this->setClient($client); |
|
101
|
20 |
|
} |
|
102
|
|
|
|
|
103
|
20 |
|
return $this->client; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Set the REST client of the backend web service |
|
108
|
|
|
* |
|
109
|
|
|
* @param Client $client REST client |
|
110
|
|
|
* |
|
111
|
|
|
* @return ReportingCloud |
|
112
|
|
|
*/ |
|
113
|
20 |
|
public function setClient(Client $client) |
|
114
|
|
|
{ |
|
115
|
20 |
|
$this->client = $client; |
|
116
|
|
|
|
|
117
|
20 |
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Return the username |
|
122
|
|
|
* |
|
123
|
|
|
* @return string |
|
124
|
|
|
*/ |
|
125
|
23 |
|
public function getUsername() |
|
126
|
|
|
{ |
|
127
|
23 |
|
return $this->username; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Set the username |
|
132
|
|
|
* |
|
133
|
|
|
* @param string $username Username |
|
134
|
|
|
* |
|
135
|
|
|
* @return ReportingCloud |
|
136
|
|
|
*/ |
|
137
|
62 |
|
public function setUsername($username) |
|
138
|
|
|
{ |
|
139
|
62 |
|
$this->username = $username; |
|
140
|
|
|
|
|
141
|
62 |
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Return the password |
|
146
|
|
|
* |
|
147
|
|
|
* @return string |
|
148
|
|
|
*/ |
|
149
|
23 |
|
public function getPassword() |
|
150
|
|
|
{ |
|
151
|
23 |
|
return $this->password; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Set the password |
|
156
|
|
|
* |
|
157
|
|
|
* @param string $password Password |
|
158
|
|
|
* |
|
159
|
|
|
* @return ReportingCloud |
|
160
|
|
|
*/ |
|
161
|
62 |
|
public function setPassword($password) |
|
162
|
|
|
{ |
|
163
|
62 |
|
$this->password = $password; |
|
164
|
|
|
|
|
165
|
62 |
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Return the base URI of the backend web service |
|
170
|
|
|
* |
|
171
|
|
|
* @return string |
|
172
|
|
|
*/ |
|
173
|
24 |
|
public function getBaseUri() |
|
174
|
|
|
{ |
|
175
|
24 |
|
if (null === $this->baseUri) { |
|
176
|
22 |
|
$this->setBaseUri(self::DEFAULT_BASE_URI); |
|
177
|
22 |
|
} |
|
178
|
|
|
|
|
179
|
24 |
|
return $this->baseUri; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Set the base URI of the backend web service |
|
184
|
|
|
* |
|
185
|
|
|
* @param string $baseUri Base URI |
|
186
|
|
|
* |
|
187
|
|
|
* @return ReportingCloud |
|
188
|
|
|
*/ |
|
189
|
24 |
|
public function setBaseUri($baseUri) |
|
190
|
|
|
{ |
|
191
|
24 |
|
$this->baseUri = $baseUri; |
|
192
|
|
|
|
|
193
|
24 |
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Get the timeout (in seconds) of the backend web service |
|
198
|
|
|
* |
|
199
|
|
|
* @return int |
|
200
|
|
|
*/ |
|
201
|
23 |
|
public function getTimeout() |
|
202
|
|
|
{ |
|
203
|
23 |
|
if (null === $this->timeout) { |
|
204
|
21 |
|
$this->setTimeout(self::DEFAULT_TIMEOUT); |
|
205
|
21 |
|
} |
|
206
|
|
|
|
|
207
|
23 |
|
return $this->timeout; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Set the timeout (in seconds) of the backend web service |
|
212
|
|
|
* |
|
213
|
|
|
* @param int $timeout Timeout |
|
214
|
|
|
* |
|
215
|
|
|
* @return ReportingCloud |
|
216
|
|
|
*/ |
|
217
|
23 |
|
public function setTimeout($timeout) |
|
218
|
|
|
{ |
|
219
|
23 |
|
$this->timeout = (int) $timeout; |
|
220
|
|
|
|
|
221
|
23 |
|
return $this; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Return the debug flag |
|
226
|
|
|
* |
|
227
|
|
|
* @return mixed |
|
228
|
|
|
*/ |
|
229
|
23 |
|
public function getDebug() |
|
230
|
|
|
{ |
|
231
|
23 |
|
if (null === $this->debug) { |
|
232
|
21 |
|
$this->setDebug(self::DEFAULT_DEBUG); |
|
233
|
21 |
|
} |
|
234
|
|
|
|
|
235
|
23 |
|
return $this->debug; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Set the debug flag |
|
240
|
|
|
* |
|
241
|
|
|
* @param bool $debug Debug flag |
|
242
|
|
|
* |
|
243
|
|
|
* @return ReportingCloud |
|
244
|
|
|
*/ |
|
245
|
23 |
|
public function setDebug($debug) |
|
246
|
|
|
{ |
|
247
|
23 |
|
$this->debug = (bool) $debug; |
|
248
|
|
|
|
|
249
|
23 |
|
return $this; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Return the test flag |
|
254
|
|
|
* |
|
255
|
|
|
* @return mixed |
|
256
|
|
|
*/ |
|
257
|
21 |
|
public function getTest() |
|
258
|
|
|
{ |
|
259
|
21 |
|
if (null === $this->test) { |
|
260
|
19 |
|
$this->setTest(self::DEFAULT_TEST); |
|
261
|
19 |
|
} |
|
262
|
|
|
|
|
263
|
21 |
|
return $this->test; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Set the test flag |
|
268
|
|
|
* |
|
269
|
|
|
* @param bool $test Test flag |
|
270
|
|
|
* |
|
271
|
|
|
* @return ReportingCloud |
|
272
|
|
|
*/ |
|
273
|
21 |
|
public function setTest($test) |
|
274
|
|
|
{ |
|
275
|
21 |
|
$this->test = (bool) $test; |
|
276
|
|
|
|
|
277
|
21 |
|
return $this; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Get the version string of the backend web service |
|
282
|
|
|
* |
|
283
|
|
|
* @return string |
|
284
|
|
|
*/ |
|
285
|
22 |
|
public function getVersion() |
|
286
|
|
|
{ |
|
287
|
22 |
|
if (null === $this->version) { |
|
288
|
20 |
|
$this->version = self::DEFAULT_VERSION; |
|
289
|
20 |
|
} |
|
290
|
|
|
|
|
291
|
22 |
|
return $this->version; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
/** |
|
295
|
|
|
* Set the version string of the backend web service |
|
296
|
|
|
* |
|
297
|
|
|
* @param string $version Version string |
|
298
|
|
|
* |
|
299
|
|
|
* @return ReportingCloud |
|
300
|
|
|
*/ |
|
301
|
2 |
|
public function setVersion($version) |
|
302
|
|
|
{ |
|
303
|
2 |
|
$this->version = $version; |
|
304
|
|
|
|
|
305
|
2 |
|
return $this; |
|
306
|
|
|
} |
|
307
|
|
|
} |
|
308
|
|
|
|