|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class HTTPClientAbstract |
|
4
|
|
|
* |
|
5
|
|
|
* @created 22.02.2019 |
|
6
|
|
|
* @author smiley <[email protected]> |
|
7
|
|
|
* @copyright 2019 smiley |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace chillerlan\HTTP\Psr18; |
|
12
|
|
|
|
|
13
|
|
|
use chillerlan\HTTP\HTTPOptions; |
|
14
|
|
|
use chillerlan\HTTP\Psr17\{ResponseFactory}; |
|
15
|
|
|
use chillerlan\Settings\SettingsContainerInterface; |
|
16
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
|
17
|
|
|
use Psr\Http\Message\StreamFactoryInterface; |
|
18
|
|
|
use Psr\Log\{LoggerInterface, NullLogger}; |
|
19
|
|
|
|
|
20
|
|
|
abstract class HTTPClientAbstract implements HTTPClientInterface{ |
|
21
|
|
|
|
|
22
|
|
|
protected HTTPOptions|SettingsContainerInterface $options; |
|
23
|
|
|
protected LoggerInterface $logger; |
|
24
|
|
|
protected ResponseFactoryInterface $responseFactory; |
|
25
|
|
|
protected ?StreamFactoryInterface $streamFactory = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* HTTPClientAbstract constructor. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( |
|
31
|
|
|
HTTPOptions|SettingsContainerInterface $options = null, |
|
32
|
|
|
ResponseFactoryInterface $responseFactory = null, |
|
33
|
|
|
LoggerInterface $logger = null |
|
34
|
|
|
){ |
|
35
|
|
|
$this->options = $options ?? new HTTPOptions; |
|
36
|
|
|
|
|
37
|
|
|
$this |
|
38
|
|
|
->setResponseFactory($responseFactory ?? new ResponseFactory) |
|
39
|
|
|
->setLogger($logger ?? new NullLogger) |
|
40
|
|
|
; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritDoc |
|
45
|
|
|
* @codeCoverageIgnore |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setLogger(LoggerInterface $logger):HTTPClientInterface{ |
|
48
|
|
|
$this->logger = $logger; |
|
49
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @inheritDoc |
|
55
|
|
|
* @codeCoverageIgnore |
|
56
|
|
|
*/ |
|
57
|
|
|
public function setResponseFactory(ResponseFactoryInterface $responseFactory):HTTPClientInterface{ |
|
58
|
|
|
$this->responseFactory = $responseFactory; |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @inheritDoc |
|
65
|
|
|
* @codeCoverageIgnore |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setStreamFactory(StreamFactoryInterface $streamFactory):HTTPClientInterface{ |
|
68
|
|
|
$this->streamFactory = $streamFactory; |
|
69
|
|
|
|
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|