Completed
Push — master ( 362a13...64ee51 )
by WEBEWEB
01:29
created

CurlConfiguration   A

Complexity

Total Complexity 39

Size/Duplication

Total Lines 511
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 39
lcom 1
cbo 1
dl 0
loc 511
rs 9.28
c 0
b 0
f 0

38 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A addHeader() 0 5 1
A clearHeaders() 0 3 1
A getAllowEncoding() 0 3 1
A getConnectTimeout() 0 3 1
A getDebug() 0 3 1
A getDebugFile() 0 3 1
A getHeaders() 0 3 1
A getHost() 0 3 1
A getHttpPassword() 0 3 1
A getHttpUsername() 0 3 1
A getProxyHost() 0 3 1
A getProxyPassword() 0 3 1
A getProxyPort() 0 3 1
A getProxyType() 0 3 1
A getProxyUsername() 0 3 1
A getRequestTimeout() 0 3 1
A getSslVerification() 0 3 1
A getUserAgent() 0 3 1
A getVerbose() 0 3 1
A removeHeader() 0 5 2
A setAllowEncoding() 0 4 1
A setConnectTimeout() 0 4 1
A setDebug() 0 4 1
A setDebugFile() 0 4 1
A setHeaders() 0 4 1
A setHost() 0 4 1
A setHttpPassword() 0 4 1
A setHttpUsername() 0 4 1
A setProxyHost() 0 4 1
A setProxyPassword() 0 4 1
A setProxyPort() 0 4 1
A setProxyType() 0 4 1
A setProxyUsername() 0 4 1
A setRequestTimeout() 0 4 1
A setSslVerification() 0 4 1
A setUserAgent() 0 4 1
A setVerbose() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Network\CURL\Configuration;
13
14
use WBW\Library\Core\Argument\ArgumentHelper;
15
use WBW\Library\Core\Argument\Exception\StringArgumentException;
16
17
/**
18
 * cURL configuration.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Network\CURL\Configuration
22
 */
23
class CurlConfiguration {
24
25
    /**
26
     * Allow encoding.
27
     *
28
     * @var bool
29
     */
30
    private $allowEncoding;
31
32
    /**
33
     * HTTP connect timeout.
34
     *
35
     * @var int
36
     */
37
    private $connectTimeout;
38
39
    /**
40
     * Debug.
41
     *
42
     * @var bool
43
     */
44
    private $debug;
45
46
    /**
47
     * Debug file.
48
     *
49
     * @var string
50
     */
51
    private $debugFile;
52
53
    /**
54
     * Headers.
55
     *
56
     * @var array
57
     */
58
    private $headers;
59
60
    /**
61
     * Host.
62
     *
63
     * @var string
64
     */
65
    private $host;
66
67
    /**
68
     * HTTP basic password.
69
     *
70
     * @var string
71
     */
72
    private $httpPassword;
73
74
    /**
75
     * HTTP basic username.
76
     *
77
     * @var string
78
     */
79
    private $httpUsername;
80
81
    /**
82
     * Proxy host.
83
     *
84
     * @var string
85
     */
86
    private $proxyHost;
87
88
    /**
89
     * Proxy password.
90
     *
91
     * @var string
92
     */
93
    private $proxyPassword;
94
95
    /**
96
     * Proxy port.
97
     *
98
     * @var int
99
     */
100
    private $proxyPort;
101
102
    /**
103
     * Proxy type.
104
     *
105
     * @var int
106
     */
107
    private $proxyType;
108
109
    /**
110
     * Proxy username.
111
     *
112
     * @var string
113
     */
114
    private $proxyUsername;
115
116
    /**
117
     * HTTP request timeout.
118
     *
119
     * @var int
120
     */
121
    private $requestTimeout;
122
123
    /**
124
     * SSL verification.
125
     *
126
     * @var bool
127
     */
128
    private $sslVerification;
129
130
    /**
131
     * User agent.
132
     *
133
     * @var string
134
     */
135
    private $userAgent;
136
137
    /**
138
     * Verbose.
139
     *
140
     * @var bool
141
     */
142
    private $verbose;
143
144
    /**
145
     * Constructor.
146
     */
147
    public function __construct() {
148
        $this->setAllowEncoding(false);
149
        $this->setConnectTimeout(0);
150
        $this->setDebug(false);
151
        $this->setDebugFile("php://output");
152
        $this->setHeaders([]);
153
        $this->setRequestTimeout(0);
154
        $this->setSslVerification(true);
155
        $this->setUserAgent("webeweb/curl-library");
156
        $this->setVerbose(false);
157
    }
158
159
    /**
160
     * Add an header.
161
     *
162
     * @param string $name The header name.
163
     * @param string $value The header value.
164
     * @return CurlConfiguration Returns this cURL configuration.
165
     * @throws StringArgumentException Throws a string argument exception if the argument is not a string.
166
     */
167
    public function addHeader($name, $value) {
168
        ArgumentHelper::isTypeOf($name, ArgumentHelper::ARGUMENT_STRING);
169
        $this->headers[$name] = $value;
170
        return $this;
171
    }
172
173
    /**
174
     * Clear the headers.
175
     *
176
     * @return CurlConfiguration Returns this cURL configuration.
177
     */
178
    public function clearHeaders() {
179
        return $this->setHeaders([]);
180
    }
181
182
    /**
183
     * Get the allow encoding.
184
     *
185
     * @return bool Returns the allow encoding.
186
     */
187
    public function getAllowEncoding() {
188
        return $this->allowEncoding;
189
    }
190
191
    /**
192
     * Get the connect timeout.
193
     *
194
     * @return int Returns the connect timeout.
195
     */
196
    public function getConnectTimeout() {
197
        return $this->connectTimeout;
198
    }
199
200
    /**
201
     * Ge the debug.
202
     *
203
     * @return bool Returns the debug.
204
     */
205
    public function getDebug() {
206
        return $this->debug;
207
    }
208
209
    /**
210
     * Get the debug file.
211
     *
212
     * @return string Returns the debug file.
213
     */
214
    public function getDebugFile() {
215
        return $this->debugFile;
216
    }
217
218
    /**
219
     * Get the headers.
220
     *
221
     * @return array Returns the headers.
222
     */
223
    public function getHeaders() {
224
        return $this->headers;
225
    }
226
227
    /**
228
     * Get the host.
229
     *
230
     * @return string Returns the host.
231
     */
232
    public function getHost() {
233
        return $this->host;
234
    }
235
236
    /**
237
     * Get the HTTP password.
238
     *
239
     * @return string Returns the HTTP password.
240
     */
241
    public function getHttpPassword() {
242
        return $this->httpPassword;
243
    }
244
245
    /**
246
     * Get the HTTP username.
247
     *
248
     * @return string Returns the HTTP username.
249
     */
250
    public function getHttpUsername() {
251
        return $this->httpUsername;
252
    }
253
254
    /**
255
     * Get the proxy host.
256
     *
257
     * @return string Returns the proxy host.
258
     */
259
    public function getProxyHost() {
260
        return $this->proxyHost;
261
    }
262
263
    /**
264
     * Get the proxy password.
265
     *
266
     * @return string Returns the proxy password.
267
     */
268
    public function getProxyPassword() {
269
        return $this->proxyPassword;
270
    }
271
272
    /**
273
     * Get the proxy port.
274
     *
275
     * @return int Returns the proxy port.
276
     */
277
    public function getProxyPort() {
278
        return $this->proxyPort;
279
    }
280
281
    /**
282
     * Get the proxy type.
283
     *
284
     * @return int Returns the proxy type.
285
     */
286
    public function getProxyType() {
287
        return $this->proxyType;
288
    }
289
290
    /**
291
     * Get the proxy username.
292
     *
293
     * @return string Returns the proxy username.
294
     */
295
    public function getProxyUsername() {
296
        return $this->proxyUsername;
297
    }
298
299
    /**
300
     * Get the request timeout.
301
     *
302
     * @return int Returns the request timeout.
303
     */
304
    public function getRequestTimeout() {
305
        return $this->requestTimeout;
306
    }
307
308
    /**
309
     * Get the SSL verification.
310
     *
311
     * @return bool Returns the SSL verification.
312
     */
313
    public function getSslVerification() {
314
        return $this->sslVerification;
315
    }
316
317
    /**
318
     * Get the user agent.
319
     *
320
     * @return string Returns the user agent.
321
     */
322
    public function getUserAgent() {
323
        return $this->userAgent;
324
    }
325
326
    /**
327
     * Get the verbose.
328
     *
329
     * @return bool Returns the verbose.
330
     */
331
    public function getVerbose() {
332
        return $this->verbose;
333
    }
334
335
    /**
336
     * Remove an header.
337
     *
338
     * @param string $name The header name.
339
     * @return void
340
     */
341
    public function removeHeader($name) {
342
        if (true === array_key_exists($name, $this->headers)) {
343
            unset($this->headers[$name]);
344
        }
345
    }
346
347
    /**
348
     * Set the allow encoding.
349
     *
350
     * @param bool $allowEncoding The allow encoding.
351
     * @return CurlConfiguration Returns this cURL configuration.
352
     */
353
    public function setAllowEncoding($allowEncoding) {
354
        $this->allowEncoding = $allowEncoding;
355
        return $this;
356
    }
357
358
    /**
359
     * Set the connect timeout.
360
     *
361
     * @param int $connectTimeout The connect timeout.
362
     * @return CurlConfiguration Returns this cURL configuration.
363
     */
364
    public function setConnectTimeout($connectTimeout) {
365
        $this->connectTimeout = $connectTimeout;
366
        return $this;
367
    }
368
369
    /**
370
     * Set the debug.
371
     *
372
     * @param bool $debug The debug.
373
     * @return CurlConfiguration Returns this cURL configuration.
374
     */
375
    public function setDebug($debug) {
376
        $this->debug = $debug;
377
        return $this;
378
    }
379
380
    /**
381
     * Set the debug file.
382
     *
383
     * @param string $debugFile The debug file.
384
     * @return CurlConfiguration Returns this cURL configuration.
385
     */
386
    public function setDebugFile($debugFile) {
387
        $this->debugFile = $debugFile;
388
        return $this;
389
    }
390
391
    /**
392
     * Set the headers.
393
     *
394
     * @param array $headers The headers
395
     * @return CurlConfiguration Returns this cURL configuration.
396
     */
397
    protected function setHeaders(array $headers) {
398
        $this->headers = $headers;
399
        return $this;
400
    }
401
402
    /**
403
     * Set the host.
404
     *
405
     * @param string $host The host.
406
     * @return CurlConfiguration Returns this cURL configuration.
407
     */
408
    public function setHost($host) {
409
        $this->host = preg_replace("/\/$/", "", trim($host));
410
        return $this;
411
    }
412
413
    /**
414
     * Set the HTTP basic password.
415
     *
416
     * @param string $httpPassword The HTTP basic password.
417
     * @return CurlConfiguration Returns this cURL configuration.
418
     */
419
    public function setHttpPassword($httpPassword) {
420
        $this->httpPassword = $httpPassword;
421
        return $this;
422
    }
423
424
    /**
425
     * Set the HTTP basic username.
426
     *
427
     * @param string $httpUsername The HTTP basic username.
428
     * @return CurlConfiguration Returns this cURL configuration.
429
     */
430
    public function setHttpUsername($httpUsername) {
431
        $this->httpUsername = $httpUsername;
432
        return $this;
433
    }
434
435
    /**
436
     * Set the proxy host.
437
     *
438
     * @param string $proxyHost The proxy host.
439
     * @return CurlConfiguration Returns this cURL configuration.
440
     */
441
    public function setProxyHost($proxyHost) {
442
        $this->proxyHost = $proxyHost;
443
        return $this;
444
    }
445
446
    /**
447
     * Set the proxy password.
448
     *
449
     * @param string $proxyPassword The proxy password.
450
     * @return CurlConfiguration Returns this cURL configuration.
451
     */
452
    public function setProxyPassword($proxyPassword) {
453
        $this->proxyPassword = $proxyPassword;
454
        return $this;
455
    }
456
457
    /**
458
     * Set the proxy port.
459
     *
460
     * @param int $proxyPort The proxy port.
461
     * @return CurlConfiguration Returns this cURL configuration.
462
     */
463
    public function setProxyPort($proxyPort) {
464
        $this->proxyPort = $proxyPort;
465
        return $this;
466
    }
467
468
    /**
469
     * Set the proxy type.
470
     *
471
     * @param int $proxyType The proxy type.
472
     * @return CurlConfiguration Returns this cURL configuration.
473
     */
474
    public function setProxyType($proxyType) {
475
        $this->proxyType = $proxyType;
476
        return $this;
477
    }
478
479
    /**
480
     * Set the proxy username.
481
     *
482
     * @param string $proxyUsername The proxy username.
483
     * @return CurlConfiguration Returns this cURL configuration.
484
     */
485
    public function setProxyUsername($proxyUsername) {
486
        $this->proxyUsername = $proxyUsername;
487
        return $this;
488
    }
489
490
    /**
491
     * Set the request timeout.
492
     *
493
     * @param int $requestTimeout The request timeout.
494
     * @return CurlConfiguration Returns this cURL configuration.
495
     */
496
    public function setRequestTimeout($requestTimeout) {
497
        $this->requestTimeout = $requestTimeout;
498
        return $this;
499
    }
500
501
    /**
502
     * Set the SSL verification.
503
     *
504
     * @param bool $sslVerification The SSL verification.
505
     * @return CurlConfiguration Returns this cURL configuration.
506
     */
507
    public function setSslVerification($sslVerification) {
508
        $this->sslVerification = $sslVerification;
509
        return $this;
510
    }
511
512
    /**
513
     * Set the user agent.
514
     *
515
     * @param string $userAgent The user agent.
516
     * @return CurlConfiguration Returns this cURL configuration.
517
     */
518
    public function setUserAgent($userAgent) {
519
        $this->userAgent = $userAgent;
520
        return $this;
521
    }
522
523
    /**
524
     * Set the verbose.
525
     *
526
     * @param bool $verbose The verbose.
527
     * @return CurlConfiguration Returns this cURL configuration.
528
     */
529
    public function setVerbose($verbose = false) {
530
        $this->verbose = $verbose;
531
        return $this;
532
    }
533
}
534