|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the fnayou/instapush-php project. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2017. Aymen FNAYOU <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Fnayou\InstapushPHP\Http; |
|
12
|
|
|
|
|
13
|
|
|
use Http\Client\Common\Plugin; |
|
14
|
|
|
use Http\Client\HttpClient; |
|
15
|
|
|
use Http\Discovery\HttpClientDiscovery; |
|
16
|
|
|
use Http\Discovery\UriFactoryDiscovery; |
|
17
|
|
|
use Http\Message\UriFactory; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AbstractHttpClientConfigurator. |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractHttpClientConfigurator |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Http\Message\UriFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $uriFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \Http\Client\HttpClient |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $httpClient; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $prependPlugins = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $appendPlugins = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \Http\Client\HttpClient $httpClient |
|
46
|
|
|
* @param \Http\Message\UriFactory $uriFactory |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(HttpClient $httpClient = null, UriFactory $uriFactory = null) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
|
51
|
|
|
$this->uriFactory = $uriFactory ?: UriFactoryDiscovery::find(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return UriFactory |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getUriFactory() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->uriFactory; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param UriFactory $uriFactory |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setUriFactory(UriFactory $uriFactory) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->uriFactory = $uriFactory; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return HttpClient |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getHttpClient() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->httpClient; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param HttpClient $httpClient |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setHttpClient(HttpClient $httpClient) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->httpClient = $httpClient; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getPrependPlugins() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->prependPlugins; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getAppendPlugins() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->appendPlugins; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param \Http\Client\Common\Plugin ...$plugins |
|
104
|
|
|
* |
|
105
|
|
|
* @return $this |
|
106
|
|
|
*/ |
|
107
|
|
|
public function appendPlugin(Plugin ...$plugins) |
|
108
|
|
|
{ |
|
109
|
|
|
foreach ($plugins as $plugin) { |
|
110
|
|
|
$this->appendPlugins[] = $plugin; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param \Http\Client\Common\Plugin ...$plugins |
|
118
|
|
|
* |
|
119
|
|
|
* @return $this |
|
120
|
|
|
*/ |
|
121
|
|
|
public function prependPlugin(Plugin ...$plugins) |
|
122
|
|
|
{ |
|
123
|
|
|
$plugins = \array_reverse($plugins); |
|
124
|
|
|
|
|
125
|
|
|
foreach ($plugins as $plugin) { |
|
126
|
|
|
\array_unshift($this->prependPlugins, $plugin); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|