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 Fig\Http\Message\RequestMethodInterface; |
17
|
|
|
use Psr\Http\Client\ClientInterface; |
18
|
|
|
use Psr\Http\Message\ResponseFactoryInterface; |
19
|
|
|
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger}; |
20
|
|
|
|
21
|
|
|
abstract class HTTPClientAbstract implements ClientInterface, LoggerAwareInterface, RequestMethodInterface{ |
22
|
|
|
use LoggerAwareTrait; |
23
|
|
|
|
24
|
|
|
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\HTTP\HTTPOptions */ |
25
|
|
|
protected SettingsContainerInterface $options; |
26
|
|
|
|
27
|
|
|
protected ResponseFactoryInterface $responseFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* HTTPClientAbstract constructor. |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
SettingsContainerInterface $options = null, |
34
|
|
|
ResponseFactoryInterface $responseFactory = null, |
35
|
|
|
LoggerInterface $logger = null |
36
|
|
|
){ |
37
|
|
|
$this->options = $options ?? new HTTPOptions; |
38
|
|
|
|
39
|
|
|
$this->setResponseFactory($responseFactory ?? new ResponseFactory); |
40
|
|
|
$this->setLogger($logger ?? new NullLogger); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @codeCoverageIgnore |
45
|
|
|
*/ |
46
|
|
|
public function setResponseFactory(ResponseFactory $responseFactory):self{ |
47
|
|
|
$this->responseFactory = $responseFactory; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|