1 | <?php |
||
18 | class HttpClientPoolItem implements HttpClient, HttpAsyncClient |
||
19 | { |
||
20 | /** |
||
21 | * @var int Number of request this client is currently sending |
||
22 | */ |
||
23 | private $sendingRequestCount = 0; |
||
24 | |||
25 | /** |
||
26 | * @var \DateTime|null Time when this client has been disabled or null if enable |
||
27 | */ |
||
28 | private $disabledAt; |
||
29 | |||
30 | /** |
||
31 | * @var int|null Number of seconds after this client is reenable, by default null: never reenable this client |
||
32 | */ |
||
33 | private $reenableAfter; |
||
34 | |||
35 | /** |
||
36 | * @var FlexibleHttpClient A http client responding to async and sync request |
||
37 | */ |
||
38 | private $client; |
||
39 | |||
40 | /** |
||
41 | * @param HttpClient|HttpAsyncClient $client |
||
42 | * @param null|int $reenableAfter Number of seconds after this client is reenable |
||
43 | */ |
||
44 | 23 | public function __construct($client, $reenableAfter = null) |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 13 | public function sendRequest(RequestInterface $request) |
|
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | 8 | public function sendAsyncRequest(RequestInterface $request) |
|
95 | |||
96 | /** |
||
97 | * Whether this client is disabled or not. |
||
98 | * |
||
99 | * Will also reactivate this client if possible |
||
100 | * |
||
101 | * @internal |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | 21 | public function isDisabled() |
|
124 | |||
125 | /** |
||
126 | * Get current number of request that is send by the underlying http client. |
||
127 | * |
||
128 | * @internal |
||
129 | * |
||
130 | * @return int |
||
131 | */ |
||
132 | 2 | public function getSendingRequestCount() |
|
136 | |||
137 | /** |
||
138 | * Return when this client has been disabled or null if it's enabled. |
||
139 | * |
||
140 | * @return \DateTime|null |
||
141 | */ |
||
142 | 21 | private function getDisabledAt() |
|
146 | |||
147 | /** |
||
148 | * Increment the request count. |
||
149 | */ |
||
150 | 21 | private function incrementRequestCount() |
|
154 | |||
155 | /** |
||
156 | * Decrement the request count. |
||
157 | */ |
||
158 | 16 | private function decrementRequestCount() |
|
162 | |||
163 | /** |
||
164 | * Enable the current client. |
||
165 | */ |
||
166 | 5 | private function enable() |
|
170 | |||
171 | /** |
||
172 | * Disable the current client. |
||
173 | */ |
||
174 | 10 | private function disable() |
|
178 | } |
||
179 |