|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry @ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
declare(strict_types=1); |
|
7
|
|
|
|
|
8
|
|
|
namespace SocialConnect\Common; |
|
9
|
|
|
|
|
10
|
|
|
use Psr\Http\Client\ClientInterface; |
|
11
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
|
12
|
|
|
use Psr\Http\Message\RequestInterface; |
|
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
14
|
|
|
use Psr\Http\Message\StreamFactoryInterface; |
|
15
|
|
|
use Psr\Http\Message\StreamInterface; |
|
16
|
|
|
|
|
17
|
|
|
class HttpStack implements RequestFactoryInterface, ClientInterface, StreamFactoryInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var ClientInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $client; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var RequestFactoryInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $requestFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var StreamFactoryInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $streamFactory; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* HttpStack constructor. |
|
36
|
|
|
* @param ClientInterface $client |
|
37
|
|
|
* @param RequestFactoryInterface $requestFactory |
|
38
|
|
|
* @param StreamFactoryInterface $streamFactory |
|
39
|
|
|
*/ |
|
40
|
455 |
|
public function __construct(ClientInterface $client, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory) |
|
41
|
|
|
{ |
|
42
|
455 |
|
$this->client = $client; |
|
43
|
455 |
|
$this->requestFactory = $requestFactory; |
|
44
|
455 |
|
$this->streamFactory = $streamFactory; |
|
45
|
455 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritDoc} |
|
49
|
|
|
*/ |
|
50
|
103 |
|
public function sendRequest(RequestInterface $request): ResponseInterface |
|
51
|
|
|
{ |
|
52
|
103 |
|
return $this->client->sendRequest($request); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritDoc} |
|
57
|
|
|
*/ |
|
58
|
103 |
|
public function createRequest(string $method, $uri): RequestInterface |
|
59
|
|
|
{ |
|
60
|
103 |
|
return $this->requestFactory->createRequest($method, $uri); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
*/ |
|
66
|
25 |
|
public function createStream(string $content = ''): StreamInterface |
|
67
|
|
|
{ |
|
68
|
25 |
|
return $this->streamFactory->createStream($content); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritDoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->streamFactory->createStreamFromFile($filename, $mode); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritDoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function createStreamFromResource($resource): StreamInterface |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->streamFactory->createStreamFromResource($resource); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|